Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

All possible ways to trigger a button click in jquery

I want to know all possible ways to trigger a button in jQuery, I tried this but it's not working,

$("#<%=btA.ClientID%>").trigger('click');

Note: its a ASP.Net button and what I want is to trigger button click so that it will trigger a code-behind click method of buttonA.

like image 612
Mathematics Avatar asked Mar 06 '13 08:03

Mathematics


Video Answer


1 Answers

Try this

$("#<%=btA.ClientID%>").click();

if it doesn't work try to alert this and check if it is getting accessed by JQ

alert($("#<%=btA.ClientID%>").length);

Have you registered the event with jquery in following manner

$(function(){
   $("#<%=btA.ClientID%>").click(function(){
   // your logic here
});
});

One more thing to confirm, are you loading this button directly on page load or you are having some page update panel which load it afterwords?

If yes then you should bind the event to button in following manner

$(document).on('click',"#<%=btA.ClientID%>", function() {...});
like image 162
K D Avatar answered Oct 05 '22 13:10

K D