- 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
264 Views
The callback function takes a single parameter; when the handler is called the JavaScript event object will be passed through it.The event object is often unnecessary and the parameter is omitted, as sufficient context is usually available when the handler is bound to know exactly what needs to be done when the handler is triggered, however there are certain attributes which you would need to be accessed.Let us see an example of isDefaultPrevented() method. The isDefaultPrevented() method checks whether event.preventDefault() was ever called on this event object.ExampleYou can try to run the following code to learn how to work with ... Read More
885 Views
Once an event handler is established, it remains in effect for the remainder of the life of the page. There may be a need when you would like to remove event handler.jQuery provides the unbind() command to remove an exiting event handler. The syntax of unbind() is as follows.The following is the description of the parameters −eventType − A string containing a JavaScript event type, such as click or submit. Refer to the next section for a complete list of event types.handler − If provided, identifies the specific listener that's to be removed.ExampleYou can try to run the following code to learn ... Read More
2K+ Views
To check the element type pf an event target, using the is() method.ExampleYou can try to run the following code to check the element type:Live Demo $(document).ready(function(){ $( "ul" ).click(function( event ) { var target = $( event.target ); if ( target.is( "li" ) ) { alert("Element is 'li'") } }); }); Click below to find out which element India US UK
543 Views
The bind( type, [data], fn ) method binds a handler to one or more events (like click) for each matched element. It can also bind custom events.Possible event values − blur, focus, load, resize, scroll, unload, click etc.Here is the description of all the parameters used by this method −type − One or more event types separated by a space.data − This is optional parameter and represents additional data passed to the event handler as event.data.fn − A function to bind to the event on each of the set of matched elements.ExampleYou can try to run the following code to learn how to ... Read More
3K+ Views
To handle a mouse right click event, use the mousedown() jQuery method. Mouse left, right and middle click can also be captured using the same method. You can try to run the following code to learn how to handle a mouse right click event:ExampleLive Demo $(document).ready(function(){ $('.myclass').mousedown(function(event) { switch (event.which) { case 1: alert('Left mouse button is pressed'); break; case 2: alert('Middle mouse button is pressed'); break; case 3: alert('Right mouse button is pressed'); break; default: alert('Nothing'); } }); }); Click me
861 Views
To handle a double click event using jQuery, use the dblclick() event. When an element is double clicked, this event occurs.ExampleYou can try to run the following code to learn how to handle double click event using jQuery −Live Demo $(document).ready(function(){ $("p").dblclick(function(){ alert("You have clicked this twice."); }); }); Double click
4K+ Views
To handle a click event using jQuery, use the click() method. You can try to run the following code to handle a link click event using jQuery −ExampleLive Demo $(document).ready(function(){ $("a").click(function(){ alert("You've clicked the link."); }); }); Click below link. Click
How can I remove everything inside of a using jQuery?
Updated on 14-Feb-2020 10:16:23
525 Views
To remove everything inside a div element, use the remove() method. You can try to run the following code to remove everything inside a element −ExampleLive Demo
$(document).ready(function(){
$(".btn").click(function(){
$("div#demo").remove();
});
});
Hide the elements inside div
Inside div- This is demo text.
Inside div- This is demo text.
Inside span- This is demo text.
Inside span- This is demo text.
525 Views
To remove everything inside a div element, use the remove() method. You can try to run the following code to remove everything inside a element −ExampleLive Demo $(document).ready(function(){ $(".btn").click(function(){ $("div#demo").remove(); }); }); Hide the elements inside div Inside div- This is demo text. Inside div- This is demo text. Inside span- This is demo text. Inside span- This is demo text.
2K+ Views
To remove all elements except the first one, use the remove() method with the slice() method in jQuery. You can try to run the following code to remove all elements except for first one using jQuery −ExampleLive Demo $(document).ready(function(){ $(".button1").click(function(){ $("span").remove(); }); $(".button2").click(function(){ $('span').slice(1).remove(); }); }); Hide all, except first element Hide all the elements This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text.
5K+ Views
To remove all child nodes from a parent, use the empty() method. The empty() method removes all child nodes from the set of matched elements.ExampleYou can try to run the following code to learn how to remove all child nodes from a parent −Live Demo jQuery empty() method $(document).ready(function() { $("div").click(function () { $(this).empty(); }); }); .div { margin:10px; padding:12px; border:2px solid #666; width:60px; } Click on any square below to see the result: ONE TWO