When I thought of writing this post, I was actually confused about the title of the post but then I ended with "Some special jQuery Events". If you know these events then they are not special for you but if you have come across them for the first time, then they are definitely special for you. So in this post, I will explain about 3 jQuery events. Which are,
See result below.
trigger: Execute all handlers and behaviors attached to the matched elements for the given event type. In simple terms, you can trigger or call other event using trigger event. For example, There are 2 buttons and from Button 1 click you want to call Button 2 click event. This you can achieve using trigger event.
toggle: Bind two or more handlers to the matched elements, to be executed on alternate clicks. This is like on/off switch. When you on the switch fan starts and when you off fan stops.
Feel free to contact me for any help related to jQuery, I will gladly help you.
- one
- trigger
- toggle
$(document).ready(function() { $("#btnDummy").one("click", function() { alert("This will be displayed only once."); }); });In this case, when button is clicked for the first time, then only the alert will be displayed.
See result below.
trigger: Execute all handlers and behaviors attached to the matched elements for the given event type. In simple terms, you can trigger or call other event using trigger event. For example, There are 2 buttons and from Button 1 click you want to call Button 2 click event. This you can achieve using trigger event.
$(document).ready(function() { $("#btnDummy1").bind("click", function() { alert("Button 1 is clicked"); $('#btnDummy2').trigger('click'); }); $("#btnDummy2").bind("click", function() { alert("Button 2 is clicked"); }); });See result below.
toggle: Bind two or more handlers to the matched elements, to be executed on alternate clicks. This is like on/off switch. When you on the switch fan starts and when you off fan stops.
$(document).ready(function() { $('#btnDummy').toggle(function() { alert('First handler for .toggle() called.'); }, function() { alert('Second handler for .toggle() called.'); }); });See result below.
Feel free to contact me for any help related to jQuery, I will gladly help you.
No comments:
Post a Comment