Bug Tracker

Modify

Ticket #2817 (closed bug: duplicate)

Opened 5 years ago

Last modified 5 years ago

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:
Blocking: Blocked by:

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

Change History

comment:1 Changed 5 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 5 years ago by flesler

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

comment:3 Changed 5 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 5 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 5 years ago by flesler

  • Status changed from new to closed
  • Resolution set to duplicate

Duplicate of #1954.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.