I have one HTML button like,
<input type="button" id="btnSubmit" name="btnName" class="btnclass" value="Click Me" />
I want to call jQuery button click event based on id
property means,
we use the code like,
$("#btnSubmit").click(function(){
////////
});
as well as call button click event based on class
property means,
we use the code like,
$(".btnclass").click(function(){
/////////
});
and my question is, I want to call the button click event based on name
property means, How to do this?
To make click event work add android:onClick attribute to the Button element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event.
The click() method simulates a mouse-click on an element. This method can be used to execute a click on an element as if the user manually clicked on it.
You can use the name property for that particular element. For example to set a border of 2px around an input element with name xyz
, you can use;
$(function() {
$("input[name = 'xyz']").css("border","2px solid red");
})
DEMO
$('element[name="element_name"]').click(function(){
//do stuff
});
in your case:
$('input[name="btnName"]').click(function(){
//do stuff
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With