Recently, using javascript(jQuery to be specific) I was working on a script that retrieves the value attribute from a hidden input field.
<input type="hidden" name="amount" id="cost" value="" />
The input had an id of cost.
For some odd reason, in ie7, when I would output the value, it would always return undefined.
alert($("input#cost").attr("value")); // returns undefined...
After much frustration, I oddly enough changed the id of that input element to price which seems to have resolved the issue?
At this point everything is working again, but I am wondering if anyone can shed some light on what might cause this type of behavior?
That kind of error is usually caused by having multiple elements with the same
id. According to the specification,idattributes need to be unique within the page.Should you need to tag multiple elements with a single identifier, you should use a class.