Adding new Custom Attribute to a HTML element.

Discussion in 'HTML' started by Alok, Jul 24, 2006.

  1. Alok

    Alok Guest

    Hi ,
    I want to know is there any way to add a custome attribute to the a
    HTML element .For example ,
    <INPUT type=text name="txtNAME1" id="txtNAME1" size=7 maxlength=7
    displayName="dspNAME1">

    In the above example the custom attribute "displayName" is not a
    standard HTML attribute.
    If I can define the same I can push the intended value and access
    the same attribute's value through javascript .

    Advance thanks for any help in this regard .

    Alok
    Alok, Jul 24, 2006
    #1
    1. Advertising

  2. Le Sun, 23 Jul 2006 17:51:19 -0700, Alok a écrit :

    > I want to know is there any way to add a custome attribute


    No.

    Mike
    --
    http://massonnet.org/ Mike Massonnet (mmassonnet) ,-.
    , ( {o\
    GnuPG 0--" 0xF8C80F97 {`"=,___) (`~
    C4DA 431D 52F9 F930 3E5B 3E3D 546C 89D9 F8C8 0F97 \ ,_.- )
    Mike Massonnet, Jul 24, 2006
    #2
    1. Advertising

  3. Gazing into my crystal ball I observed "Alok" <>
    writing in news::

    > Hi ,
    > I want to know is there any way to add a custome attribute to the a
    > HTML element .For example ,
    > <INPUT type=text name="txtNAME1" id="txtNAME1" size=7 maxlength=7
    > displayName="dspNAME1">
    >
    > In the above example the custom attribute "displayName" is not a
    > standard HTML attribute.
    > If I can define the same I can push the intended value and access
    > the same attribute's value through javascript .
    >
    > Advance thanks for any help in this regard .
    >


    You cannot add custom attributes, but you can do what you are setting out
    to do with a little javascript and server side script. There's an
    example at <http://www.intraproducts.com/usenet/requiredform.asp>.
    Notice the form is prefilled with values that help the user (server
    side). When the user focuses on the element, the value disappears
    (javascript).

    This script also uses CSS to help advise the user that something is
    missing or wrong. There are no tables involved, only CSS and clean
    markup.


    --
    Adrienne Boswell at Home
    Arbpen Web Site Design Services
    http://www.cavalcade-of-coding.info
    Please respond to the group so others can share
    Adrienne Boswell, Jul 24, 2006
    #3
  4. Alok

    Toby Inkster Guest

    Alok wrote:

    > In the above example the custom attribute "displayName" is not a
    > standard HTML attribute.


    Try something like 'class="displayName:dspNAME1"'

    The 'class' attribute is a great way of storing extra info. See for
    example:

    http://message-id.net/5n.co.uk

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Jul 24, 2006
    #4
  5. Alok

    Andy Dingley Guest

    Alok wrote:

    > I want to know is there any way to add a custome attribute to the a
    > HTML element .


    Yes, just stick them in there. It's not valid, but it's also not
    harmful (so long as you avoid obviously hazardous names). There is a
    long, well-established and well-supported practice in HTML that adding
    unknown elements can be a problem but adding unknown attributes is
    safely and quietly ignored.
    Andy Dingley, Jul 24, 2006
    #5
  6. In article <>,
    "Andy Dingley" <> wrote:

    > Yes, just stick them in there. It's not valid, but it's also not
    > harmful (so long as you avoid obviously hazardous names). There is a
    > long, well-established and well-supported practice in HTML that adding
    > unknown elements can be a problem but adding unknown attributes is
    > safely and quietly ignored.


    To quote a past poster that I miss, "you can't just make shit up" ;-)

    leo

    --
    <http://web0.greatbasin.net/~leo/>
    Leonard Blaisdell, Jul 25, 2006
    #6
  7. Alok

    Andy Dingley Guest

    Leonard Blaisdell wrote:

    > To quote a past poster that I miss, "you can't just make shit up" ;-)


    You clearly can, it's just a question of what the consequences are.

    This doesn't break anything, and it's useful for some DHTML purposes. I
    can't think of _ANY_ occasion when it will break a browser (any
    platform).

    It's not entirely portable, and it will be discarded by most HTML /
    XHTML / WML transcoders. So don't expect it to work on phone networks,
    and certainly code your DHTML to fail robustly if the expected
    attribute unexpectedly vanishes.
    Andy Dingley, Jul 25, 2006
    #7
  8. Alok

    Ed Mullen Guest

    Leonard Blaisdell wrote:
    > In article <>,
    > "Andy Dingley" <> wrote:
    >
    >> Yes, just stick them in there. It's not valid, but it's also not
    >> harmful (so long as you avoid obviously hazardous names). There is a
    >> long, well-established and well-supported practice in HTML that adding
    >> unknown elements can be a problem but adding unknown attributes is
    >> safely and quietly ignored.

    >
    > To quote a past poster that I miss, "you can't just make shit up" ;-)
    >
    > leo
    >


    Get your facts first, and then you can distort them as much as you
    please. - Mark Twain

    :-D

    --
    Ed Mullen
    http://edmullen.net
    http://mozilla.edmullen.net
    http://abington.edmullen.net
    The best audience is intelligent, well-educated, and a little drunk. -
    Alben W. Barkley (1877-1956)
    Ed Mullen, Jul 25, 2006
    #8
  9. Alok

    Page Notes

    Joined:
    Jan 29, 2009
    Messages:
    1
    Location:
    Waterford, CT
    Adding new properties and attributes

    Given that so many of us want to store data in HTML elements, I sure hope that the XHTML folks find a way to accommodate that. I'm specifically talking about things like the following:

    <p nref="#myAnchorID">some text to serve as a link source</p>

    <p style="color:#009900; skin:green-box" id="myAnchorID">
    an annotation for the link source </p>
    Page Notes, Jan 29, 2009
    #9
  10. Alok

    kewp

    Joined:
    Feb 15, 2010
    Messages:
    2
    well i just wrote the following html

    <div id="mydiv" thing="hi"> </div>

    and the following javascript worked in chrome, firefox and ie

    alert(document.getElementById("mydiv").getAttribute("thing"));

    ...
    kewp, Feb 15, 2010
    #10
  11. Alok

    kewp

    Joined:
    Feb 15, 2010
    Messages:
    2
    well i just wrote the following html

    <div id="mydiv" thing="hi"> </div>

    and the following javascript worked in chrome, ie and firefox

    mydiv = document.getElementById("mydiv");
    alert(mydiv.getAttribute("thing"));

    ...
    kewp, Feb 15, 2010
    #11
  12. Alok

    michaelhugs

    Joined:
    Mar 19, 2010
    Messages:
    1
    Verified. kewp, you tha man!
    michaelhugs, Mar 19, 2010
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. anonymous
    Replies:
    1
    Views:
    5,920
  2. =?Utf-8?B?TWFyaw==?=
    Replies:
    4
    Views:
    616
    =?Utf-8?B?TWFyaw==?=
    Dec 14, 2006
  3. perspolis
    Replies:
    1
    Views:
    2,533
    Mark Rae
    Jan 23, 2007
  4. Joe Kovac
    Replies:
    2
    Views:
    921
    Joe Kovac
    May 2, 2007
  5. Replies:
    1
    Views:
    498
    Pavel Lepin
    Feb 19, 2008
Loading...

Share This Page