jQuery ambiguous of val() or attr('value') in IE 7


When using <button></button>, there is an ambiguous of val() and attr('value')

For example:


<button id="button_tag" value="val works">val doesn't work</button> $(function()) { $('#button_tag').val(); //output: val doesn't work $('#button_tag').attr('value'); //output: val doesn't work });


IE7 thinks the tag's text is the value and stops jQuery getting the attribute value. IE7 treats val() the same as attr('value').

To solve just add another attribute that's not ambiguous.

Leave a comment