I would like to pass the value of an HTML tag to a jQuery alert box, but I’m not getting any luck. I basically want to pass either “1” or “2” to the alert box. I keep getting “undefined” in the alert box.
<button class="up" value="1">
<button class="down" value="2">
$(document).ready(function(){
$(".up,.down").click(function(){
alert(this.value);
});
)};
I’m doing this for an ajax function, but I need to make sure I can pass the values first, so the alert box is for debugging.
That’s because the value of a button is what’s between the
<button></button>tags in IE7, to be safe you can instead you can use for example adata-attribute, like this:With matching script:
You can test it here.