Bug Tracker

Opened 13 years ago

Closed 13 years ago

#2817 closed bug (duplicate)

val() method doesn't work correctly for IE and <button />

Reported by: nberardi Owned by:
Priority: major Milestone: 1.2.4
Component: core Version: 1.2.3
Keywords: Cc:
Blocked by: Blocking:


The val method seems to return the inner text of a <button /> in IE.

<button id="mybutton" value="1">Change Value</button>

In Firefox the value comes back as 1, however in IE the value comes back as "Change Value".

Change History (5)

comment:1 Changed 13 years ago by nberardi

Probably related to this http://msdn.microsoft.com/en-us/library/ms535211(VS.85).aspx

When the BUTTON element is submitted in a form, the innerText value is submitted.

comment:2 Changed 13 years ago by flesler

Can't you just use .html() or .text() ? probably one those will work as you expect.

comment:3 Changed 13 years ago by nberardi

No I don't think you are understanding the problem. The value attribute is ignored in IE, and the text of the button is returned. This is different than all the other browsers which support the standard. I wanted everybody to be aware of this, because jQuery is usually a good buffer between browser incompatibilities.

.html() and .text() both return the innerText of the button element. However I am looking for the value attribute which is usually returned by val(). However in the case of IE the innerText is returned in the val() method.

comment:4 Changed 13 years ago by luka.kladari

a really ugly/bad workaround (credit: http://odyniec.net/projects/iefixbuttons/):

var rawval = $("button").get(0).outerHTML.match(/value\s*=\s*['"](['"]*)['"]/); var val = (rawval ? rawval[1] : );

to be combined with if($.browser.msie)

this will fail in cases like value="bla'bla'bla", which are perfectly valid in HTML

comment:5 Changed 13 years ago by flesler

Resolution: duplicate
Status: newclosed

Duplicate of #1954.

Note: See TracTickets for help on using tickets.