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

A

ajschuster

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)
 
R

RobG

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.


[...]
 
T

Tim Slattery

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

VK

(e-mail address removed) 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'))
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top