By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

New property difference between IE and Firefox

P: n/a
Hi All,
Can someone please explain why the following code works in IE but
not firefox please.
In ie I get an alert box with "mynewprop" but in Firefox I get
"undefined".

Help much appreciated.

Ta!!

Paul

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Untitled Document</title>

<script type="text/javascript">
function init() {
var hello=document.getElementById('hello');
alert(hello.newprop);
}
</script>
</head>

<body onload="init();">
<a id="hello" newprop="mynewprop">
</a>
</body>
</html>

Oct 14 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
VK

Pauljh wrote:
Hi All,
Can someone please explain why the following code works in IE but
not firefox please.
In ie I get an alert box with "mynewprop" but in Firefox I get
"undefined".

Help much appreciated.

Ta!!

Paul

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Untitled Document</title>

<script type="text/javascript">
function init() {
var hello=document.getElementById('hello');
alert(hello.newprop);
}
</script>
</head>

<body onload="init();">
<a id="hello" newprop="mynewprop">
</a>
</body>
</html>
What you are getting on document.getElementById('hello') is DOM
Interface to the element, not the element itself. And Firefox doesn't
expose custom attributes in the DOM Interface. For an universal
coverage of custom attributes you should manipulate element's node
directly by using hasAttribute, getAttribute, setAttribute methods.

Use this instead:

function init() {
var hello=document.getElementById('hello');
alert(hello.getAttribute('newprop'));
}

Oct 14 '06 #2

P: n/a

VK wrote:
Pauljh wrote:
<snip>

What you are getting on document.getElementById('hello') is DOM
Interface to the element, not the element itself. And Firefox doesn't
expose custom attributes in the DOM Interface. For an universal
coverage of custom attributes you should manipulate element's node
directly by using hasAttribute, getAttribute, setAttribute methods.

Use this instead:

function init() {
var hello=document.getElementById('hello');
alert(hello.getAttribute('newprop'));
}
VK,
Brilliant, thanks!!

Oct 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.