Retrieve Button value with jQuery -


A simple one, I'm trying to get the value attribute of a button when pressed while using jQuery Here's what I do:

  & lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ ('.my_button'). Click (function () {warning ($ (this) .val ());});}); & Lt; / Script & gt; & Lt; Button class = "my_button" name = "button name" value = "button value" & gt; Button label & lt; / Button & gt;  

My warning display in Firefox is 'Button Well' which is great but this 'Button Label' displays in IE 7.

Do I always use jQuery to get the value of the button? ?

Many thanks.

Answer: I now

  & lt; Input class = "using my_button" type = "image" src = "whatever.png" value = "buttonValue" />  

I know that it was posted some time ago, but if a person Answer and actually want to use a button element instead of an input element ...

You can not .attr ('value') or .val () IE with both a single button in IE both .val () and .attr ("value"), instead of the actual value of the value element of the button element Describes as text label (content).

You can work around it temporarily by removing the label of the button:

  var getButtonValue = function ($ button) {var label = $ button.text ( ); $ Button.text (''); Var button value = $ button.val (); $ Button.text (label); Return button value; }  

There are some other quirks with buttons in IE I have posted.


Comments