- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 766 Articles for JQuery
133 Views
To store and reproduce jQuery events, use console to log.ExampleYou can try to run the following code to learn how to store and reproduce jQuery events:Live Demo $(document).ready(function(){ window.events = [] $("#track").click(function(event){ window.events.push(event) $.each(window.events, function(i, item){ console.log(i, item); }); }); }); Track
119 Views
Some of the jQuery events, do not bubble such as mouseenter do not bubble. Let us see an example of such events.ExampleYou can try to run the following code to learn how to work with jQuery events, which do not bubble,Live Demo $(document).ready(function(){ $("p").mouseenter(function(){ $("p").css("background-color", "red"); }); $("p").mouseleave(function(){ $("p").css("background-color", "blue"); }); }); Demo Text - Keep the mouse pointer here.
153 Views
stopPropogation() methodTo stop the bubbling of an event to parent elements, use the stopPropagation() method.ExampleYou can try to run the following code to learn how to work with stopPropogation() method:Live Demo jQuery stopPropagation() method $(document).ready(function() { $("div").click(function(event){ alert("This is : " + $(this).text()); event.stopPropagation(); ... Read More
763 Views
To prioritize jQuery events, use the event.stopPropagation().ExampleYou can try to run the following code to learn how to prioritize using stopPropogation() method:Live Demo $(document).ready(function(){ var timer; function out(s) { if (timer) { clearTimeout(timer); timer = null; } $("#demo").append(s + ""); timer = setTimeout(function() { $("#demo").append("-------" + ""); timer = null; }, 100); } $(".li").find('input').click(function(e){ out('li>input'); if ($(this).parent().hasClass("stop")) { e.stopPropagation(); } }); $(".li").click(function(e){ out('li'); }); $('input').click(function(e){ out('input'); if ($(this).parent().hasClass("stop")) { e.stopPropagation(); } }); }); Demo Demo using stop propagation method
1K+ Views
The jQuery setTimeout() method is used to set an interval for events to fire.ExampleHere, we will set an interval of 3 seconds for an alert box to load using jQuery events:Live Demo $(document).ready(function(){ $("#button1").click(function(){ setTimeout("alert('Hello World!');", 3000); }); }); Click Click the above button and wait for 3 seconds. An alert box will generate after 3 seconds.
2K+ Views
To detect loading of an image with jQuery, use the load() event handler.Note: The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.ExampleYou can try to run the following code to learn how to detect when image loads:Live Demo $(document).ready(function(){ $("img").load(function(){ alert("Image successfully loaded."); }); }); Note: The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.
167 Views
Ti check whether jQuery events are blocking, use the .triggerHandler() method, since it returns anything the last event handler for that event on that selector returns.ExampleLive Demo $(document).ready(function(){ var myValue = "John"; $("body").bind("eventName", function(e, value) { return value + " Jacob"; }); var result = $("body").triggerHandler("eventName", myValue); alert(result); }); This shows an alert box.
2K+ Views
To bind events on dynamically created elements, you need to load dynamically. You can try to run the following code to learn how to bind events on dynamically created elements. Here, we will generate a new list item on button click.ExampleLive Demo $(document).ready(function(){ $("button").click(function(){ $("ul").append("new item ×"); }); $(document).on("click", "a.del" , function() { $(this).parent().remove(); }); }); Add Click the above button to dynamically add new list items. You can remove it later. item
195 Views
Let’s say an event handler is attached to your element. For example,$('#foo').click(function() { console.log('clicked!') });Then you can debug it like this:For jQuery 1.3.xvar cEvent = $('#foo').data("events").click; jQuery.each(cEvent, function(key, value) { console.log(value) }) For jQuery 1.4.xvar cEvent = $('#foo').data("events").click; jQuery.each(cEvent, function(key, handlerObj) { console.log(handlerObj.handler) }) For jQuery 1.8.x+var cEvents = $._data($('#foo')[0], "events").click; jQuery.each(cEvents, function(key, handlerObj) { console.log(handlerObj.handler) })
841 Views
jQuery load() methodThe load() method is used to attach event handler to load event.ExampleYou can try to run the following code to learn how to work with jQuery load() method.Note: The method deprecated in jQuery 1.8. It got finally removed in jQuery 3.0. To run the following code, add jQuery version lesser than 1.8, Live Demo $(document).ready(function(){ $("img").load(function(){ alert("This is an image."); }); }); This image will load only in jQuery version lesser than 1.8 jQuery ready() methodEasily specify what ... Read More