Retrieve Button value with jQuery
Posted
by Simon Hutton
on Stack Overflow
See other posts from Stack Overflow
or by Simon Hutton
Published on 2009-01-28T09:55:54Z
Indexed on
2010/04/06
1:03 UTC
Read the original article
Hit count: 304
jQuery
A simple one, I'm trying to retrieve the value attribute of a button when its been pressed using jQuery, here's what I have:
<script type="text/javascript">
$(document).ready(function() {
$('.my_button').click(function() {
alert($(this).val());
});
});
</script>
<button class="my_button" name="buttonName" value="buttonValue">
Button Label</button>
In Firefox my alert displays 'buttonValue' which is great but in IE7 it displays 'Button Label'.
What jQuery should I use to always get the button's value? Or should I be using a different approach?
Many thanks.
ANSWER: I'm now using
<input class="my_button" type="image" src="whatever.png" value="buttonValue" />
© Stack Overflow or respective owner