Closed Bug 201972 Opened 21 years ago Closed 21 years ago

Element.getAttribute returns null instead of empty string where the attribute does not exist.

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 108480

People

(Reporter: gerard_mason, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.3) Gecko/20030312
Build Identifier: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.3) Gecko/20030312

Per the Document Object Model (Core) Level 1 spec on the W3C site
(http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html#ID-BBACDC08)
 an Element's getAttribute method should return "The Attr value as a string, or
the empty string if that attribute does not have a specified or default value.".
In Mozilla it seems to be returning null instead (embarassingly, IE 6 gets it
right). I have changed my test from 'if ( "" == id )' to 'if ( ! ( id > "" ) )'
to get around it, so it isn't a show-stopper, but it does seem to be a bug.


Reproducible: Always

Steps to Reproduce:
1. var id = currentElement.getAttribute ( "id" );
2. (where the current element does not, in fact, have an id)
3. if ( "" == id )

Actual Results:  
Mozilla does not execute the body of the if statement.

Expected Results:  
Mozilla executes the body of the if statement.
> (embarassingly, IE 6 gets it right)

Actually, it just gets it inconsistent.  See comments in bug 193014

*** This bug has been marked as a duplicate of 193014 ***
Status: UNCONFIRMED → RESOLVED
Closed: 21 years ago
Resolution: --- → DUPLICATE
Component: DOM: Core → DOM: Core & HTML
QA Contact: desale → general
Assignee: general → nobody
OS: Windows NT → All
Hardware: x86 → All
You need to log in before you can comment on or make changes to this bug.