Defining Your Own Attribute in an HTML Tag

Discussion in 'HTML' started by Herman, Jun 6, 2006.

  1. Herman

    Herman Guest

    Is it illegal to define your own attributes that are not defined by
    HTML standards? It sounds stupid, but would this work:

    <td id='cell' info='Information stored here'>

    Then in javascript:

    var info = document.getElementById('cell').info;

    The attribute wouldn't have an effect on the element itself, but it
    would act as an information holder for the particular element.
    This idea to me screams conflict with W3 standards, but its an idea
    that would seemingly make things easier for me.
    Any thoughts?
    Thanks a lot.
    Herman, Jun 6, 2006
    #1
    1. Advertising

  2. Gazing into my crystal ball I observed "Herman" <>
    writing in news::

    > Is it illegal to define your own attributes that are not defined by
    > HTML standards? It sounds stupid, but would this work:
    >
    ><td id='cell' info='Information stored here'>
    >
    > Then in javascript:
    >
    > var info = document.getElementById('cell').info;
    >
    > The attribute wouldn't have an effect on the element itself, but it
    > would act as an information holder for the particular element.
    > This idea to me screams conflict with W3 standards, but its an idea
    > that would seemingly make things easier for me.
    > Any thoughts?
    > Thanks a lot.
    >
    >


    That trouble with doing something like at is that because it is non-
    standard, it may break in some browsers, or it may break some time in the
    future.


    --
    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, Jun 6, 2006
    #2
    1. Advertising

  3. Herman wrote:

    > Is it illegal to define your own attributes that are not defined by
    > HTML standards?


    You won't go to jail for it, but it is invalid.

    > It sounds stupid, but would this work:
    >
    > <td id='cell' info='Information stored here'>


    I would not call it 'info', chances are to high that this will clash with
    future HTML versions (ha ha) or browser specific extensions. Call it
    e.g. 'xHermanInfo' (a more conventional 'x-herman-info' would be allowed as
    an attribute, but will cause trouble in JS...)

    > Then in javascript:
    >
    > var info = document.getElementById('cell').info;


    This may or may not work. Browsers are free to ignore tags and attributes
    that they do not understand, so your info attribute may not end up in the
    DOM. Hey, but this is JavaScript, so you write your scripts anyway in a way
    that degrades gracefully, if required features are not available... You do?

    > The attribute wouldn't have an effect on the element itself, but it
    > would act as an information holder for the particular element.
    > This idea to me screams conflict with W3 standards, but its an idea
    > that would seemingly make things easier for me.
    > Any thoughts?
    > Thanks a lot.


    You can get the same (if the information is always accessed by the elements
    ID) by using a JavaScript array that maps 'cell' -> 'Information stored
    here'.

    --
    Benjamin Niemann
    Email: pink at odahoda dot de
    WWW: http://pink.odahoda.de/
    Benjamin Niemann, Jun 6, 2006
    #3
    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. shruds
    Replies:
    1
    Views:
    757
    John C. Bollinger
    Jan 27, 2006
  2. Stylus Studio
    Replies:
    0
    Views:
    388
    Stylus Studio
    May 1, 2006
  3. c676228
    Replies:
    3
    Views:
    163
    c676228
    Sep 14, 2006
  4. Josh Cheek

    Defining your own typecaster

    Josh Cheek, Apr 25, 2010, in forum: Ruby
    Replies:
    4
    Views:
    109
    MustModify
    Apr 26, 2010
  5. David Filmer
    Replies:
    17
    Views:
    254
    J. Romano
    Aug 18, 2004
Loading...

Share This Page