Defining Your Own Attribute in an HTML Tag

H

Herman

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.
 
A

Adrienne Boswell

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.
 
B

Benjamin Niemann

Herman said:
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'.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top