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

NEED HELP!! Firefox not recognizing the "name" property?!?!?!

P: n/a
I cannot get my Javascript to work in Firefox. I am just trying to
access the .name property of a DIV tag but it keeps coming back as
"undefined". The same code works in IE and it works in Safari.... and
if I change it to .id instead of .name it can read that so why wouldn't
it be able to read the .name?

I need urgent help!! Here's my code....

var item = null;

if (document.body.getElementsByTagName) {
item = document.body.getElementsByTagName('DIV');
} else if (document.body.all) {
item = document.body.all.tags('DIV');
}

// normally this next part is in a for loop that goes through the
whole array. each time it comes back as undefined
alert("Variable: " + item[4].name)

Apr 7 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
aj********@gmail.com wrote:
I cannot get my Javascript to work in Firefox. I am just trying to
access the .name property of a DIV tag but it keeps coming back as
"undefined". The same code works in IE and it works in Safari.... and
if I change it to .id instead of .name it can read that so why wouldn't
it be able to read the .name?


There is no name attribute for DIV elements in the HTML 4 specification.
Support for non-standard attributes on HTML elements can't be assumed,
Firefox does not appear to support DIV name attributes when added via HTML.

<URL:http://www.w3.org/TR/html4/struct/global.html#edef-DIV>
You can add a name attribute to the associated DOM element object using script.
[...]
--
Rob
Apr 7 '06 #2

P: n/a
aj********@gmail.com wrote:
I cannot get my Javascript to work in Firefox. I am just trying to
access the .name property of a DIV tag but it keeps coming back as
"undefined". The same code works in IE and it works in Safari.... and
if I change it to .id instead of .name it can read that so why wouldn't
it be able to read the .name?


"name" attribute is not in the WWW standard for the DIV element, and
Firefox is *very* standards compliant. Use the "id" attribute instead.

--
Tim Slattery
Sl********@bls.gov
Apr 7 '06 #3

P: n/a
Tim Slattery wrote:
aj********@gmail.com wrote:
I cannot get my Javascript to work in Firefox. I am just trying to
access the .name property of a DIV tag but it keeps coming back as
"undefined". The same code works in IE and it works in Safari.... and
if I change it to .id instead of .name it can read that so why wouldn't
it be able to read the .name?
"name" attribute is not in the WWW standard for the DIV element, and
Firefox is *very* standards compliant.


Well, at least far more so than IE :)
Use the "id" attribute instead.


"name" should only be used for form elements, really. "id" is definitely
more compliant for DIVs
Apr 10 '06 #4

P: n/a
VK
aj********@gmail.com wrote:
alert("Variable: " + item[4].name)

It was already pointed that "name" attribute is not standard for DIV's.
Firefox still parses it and adds to the DOM tree (you can see the
relevant node in Tools>DOM Inspector), but it doesn't reflect it in the
"scriptable incarnation" of the element (sorry for this ugly term, but
the phenomen needs to be called somehow).

If for some reason(?) you absolutely need to use name's instead of id's
then:

alert("Variable: " + item[4].getAttribute('name'))

Apr 10 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.