Connecting Tech Pros Worldwide Forums | Help | Site Map

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

ajschuster@gmail.com
Guest
 
Posts: n/a
#1: Apr 7 '06
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)


RobG
Guest
 
Posts: n/a
#2: Apr 7 '06

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


ajschuster@gmail.com wrote:[color=blue]
> 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?[/color]

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
Tim Slattery
Guest
 
Posts: n/a
#3: Apr 7 '06

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


ajschuster@gmail.com wrote:
[color=blue]
>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?[/color]

"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
Slattery_T@bls.gov
Tony
Guest
 
Posts: n/a
#4: Apr 10 '06

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


Tim Slattery wrote:[color=blue]
> ajschuster@gmail.com wrote:[color=green]
>>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?[/color]
>
> "name" attribute is not in the WWW standard for the DIV element, and
> Firefox is *very* standards compliant.[/color]

Well, at least far more so than IE :)
[color=blue]
> Use the "id" attribute instead.[/color]

"name" should only be used for form elements, really. "id" is definitely
more compliant for DIVs
VK
Guest
 
Posts: n/a
#5: Apr 10 '06

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


ajschuster@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'))

Closed Thread