This example demonstrates how you know event is executed by trigger or a human. If you want to your particular code only execute when a manual click and not when trigger click.
In below example there is click event on both button when you click on Second Button I have execute the click event of First Button with the help of trigger, But in First Button click event code I am able to determine it is fired by trigger or manually.
$('.btnFirst').click(function (e) {
if (e.originalEvent != undefined) {
alert('First Button Clicked By Human');
}
else {
alert('First Button Clicked By Trigger');
}
});
CODE
<!DOCTYPE html> <html> <head> <title>jQuery With Example</title> <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $('.btnFirst').click(function (e) { if (e.originalEvent != undefined) { alert('First Button is Clicked By Human'); } else { alert('First Button is Clicked By Trigger'); } }); $('.btnSecond').click(function () { $('.btnFirst').trigger('click'); }); }); </script> </head> <body> <div class="Container"> <button type="button" class="btnFirst">First Button</button> <button type="button" class="btnSecond">Second Button</button> <p>Please click on these button to check event is fired by human or trigger.</p> </div> </body> </html>
DISPLAY
Please click on these button to check event is fired by human or trigger.
No comments :
Please Give Your Feedback