Skip to main content

Bug Tracker

Side navigation

#2817 closed bug (duplicate)

Opened May 07, 2008 02:22PM UTC

Closed October 17, 2008 02:38PM UTC

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:
Description

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".

Attachments (0)
Change History (5)

Changed May 07, 2008 02:34PM UTC by nberardi comment:1

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.

Changed May 16, 2008 06:33PM UTC by flesler comment:2

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

Changed May 22, 2008 06:31PM UTC by nberardi comment:3

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.

Changed October 17, 2008 10:46AM UTC by luka.kladari comment:4

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

Changed October 17, 2008 02:38PM UTC by flesler comment:5

resolution: → duplicate
status: newclosed

Duplicate of #1954.