[jQuery] jQuery attr method and getAttributeNode

[jQuery] jQuery attr method and getAttributeNode


jQuery's attr method returns something I wasn't expecting in IE. I
think I may have found a bug, but I may be misunderstanding
something. Here's the (very short) HTML source example demonstrating
my "bug":
<html>
<head></head>
<body>
<form>
<fieldset>
<legend>Change Your Language</legend>
<button value="testValue" name="testName" type="submit"
class="accessAid">
<img border="0" alt="" src="test.gif"/>
</button>
</form>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
alert($vpws('button').attr('value'));
</script>
</html>
I expected an alert box that would say "testValue". This does happen
in Firefox. However, in IE 7.0 I get the inner HTML of the button
element ("<img border...."). I started poking around in jQuery's
attr, and I found the culprit:
if( jQuery.nodeName( elem, "form" ) &&
elem.getAttributeNode(name) )
return elem.getAttributeNode( name ).nodeValue;
return elem[ name ];
In IE, elem.getAttributeNode(name).nodeValue is the value I expect,
but since the node name is not "form" it returns elem[name]. I
understand the logic behind using getAttributeNode (well, I would use
getAttribute) for form elements, but why isn't the same logic applied
to all DOM elements? I don't want the Javascript property named
value, I want the DOM attribute named value. Would somebody confirm
this as a bug or explain to me why this code is correct?
Thanks,
Benjamin Stover