user-defined element properties: cross-browser?

T

Timo

I've noticed that this is possible in IE:

<span class='sweetfeature' myproperty='Napoleon Dynamite'
onclick="ShowProperty(this);" >
Click here for the name of a hilarious movie.
</span>

and then in a script:

function ShowProperty(e) {
alert(e.myproperty);
// or
// alert(e['myproperty']);
}

Is there a counterpart functionality in Firefox, NS, and Opera, or is this a
proprietary MSFT feature that the other browser vendors do not support?
Thanks
TR
 
D

Dietmar Meier

Timo said:
Is there a counterpart functionality in Firefox, NS, and Opera

Depends on the doctype you use. What you showed is not valid HTML.

ciao, dhgm
 
M

Martin Honnen

Timo said:
I've noticed that this is possible in IE:

<span class='sweetfeature' myproperty='Napoleon Dynamite'
onclick="ShowProperty(this);" >
Click here for the name of a hilarious movie.
</span>

and then in a script:

function ShowProperty(e) {
alert(e.myproperty);
// or
// alert(e['myproperty']);
}

Is there a counterpart functionality in Firefox, NS, and Opera, or is this a
proprietary MSFT feature that the other browser vendors do not support?

The core DOM offers the getAttribute method for element objects so
if (e.getAttribute) {
alert(e.getAttribute('myproperty'));
}
is probably what you are looking for.
 
T

Timo

Thanks for the reply, Dietmar. Do I understand you correctly, that it would
be possible to achieve this user-defined property functionality
cross-browser, simply by declaring the appropriate doctype?
TR
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top