Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Defining Your Own Attribute in an HTML Tag

Reply
Thread Tools

Defining Your Own Attribute in an HTML Tag

 
 
Herman
Guest
Posts: n/a
 
      06-06-2006
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.

 
Reply With Quote
 
 
 
 
Adrienne Boswell
Guest
Posts: n/a
 
      06-06-2006
Gazing into my crystal ball I observed "Herman" <>
writing in news: ups.com:

> 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

 
Reply With Quote
 
 
 
 
Benjamin Niemann
Guest
Posts: n/a
 
      06-06-2006
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining your own typecaster Josh Cheek Ruby 4 04-26-2010 02:47 PM
[ANNOUNCE] Defining your own Functions in XQuery Stylus Studio XML 0 05-01-2006 07:13 PM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Your own photos in your own book Frank ess Digital Photography 1 12-09-2004 05:54 PM
defining or not defining destructors johny smith C++ 8 07-02-2004 08:51 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57