Closed Bug 61106 Opened 25 years ago Closed 25 years ago

Receiving "undefined" as element.tagName in the following script exits the script

Categories

(Core :: JavaScript Engine, defect, P3)

x86
Windows NT
defect

Tracking

()

VERIFIED INVALID

People

(Reporter: ruairif, Assigned: rogerl)

Details

Whenever I try to run the script detailed below, the script is terminated at the first entry into the for loop. I have traced this back to the .tagName method.Whenever "undefined" is returned for this, it exits the script even though I am testing for "undefined" in the first If statement. I can't upload an example because of college proxy settings, but heres a snippet of the code: ... for(i=0;i<parentDiv.childNodes.length;i++){ var current = parentDiv.childNodes[i]; if(current.tagName!="undefined"){ if(current.style.display!="none") current.style.display="none"; else current.style.display=""; } } ... parentDiv is a var that just holds the parent node of the object the script acts upon.This for loop does not execute past the first if statement
I think you've got to check for the value undefined, not the string "undefined". For example, in the standalone JS shell, testing for an uninitialized variable: js> var x js> x == undefined true js> x == "undefined" false js> x != undefined false js> x != "undefined" true Please let us know what happens if you replace your test if(current.tagName!="undefined") with: if(current.tagName!= undefined ) Thanks -
As soon as I posted, I realised the mistake and tried it with ==null instead.This returned true, yet the script still didn't work.Now, using ==undefined, the script is working again. Label this one a false alarm, perhaps, blamed on a too hasty bug reporter! Apologies for the error. Still, should there be a difference between the action of null and undefined?
and now, a minute later, null appears to work correctly (IE5 doesn'y know undefined).Oh, blame it on the late hour (its 1am over here).I'm sorry about this.But honestly, it didn't work the first time! cflynn
No problem - glad everything is working. Thanks for using Bugzilla! Have to resolve this bug as invalid, however -
Status: UNCONFIRMED → RESOLVED
Closed: 25 years ago
Resolution: --- → INVALID
Marking Verified -
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.