Found 10711 Articles for Web Development

How to handle a link click event using jQuery?

David Meador
Updated on 14-Feb-2020 10:25:09

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

David Meador
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.

How can I remove all elements except the first one using jQuery?

Amit D
Updated on 14-Feb-2020 10:15:16

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.

How to remove all child nodes from a parent using jQuery?

Amit D
Updated on 14-Feb-2020 10:14:03

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                

How to use jQuery.insertAfter() method in jQuery?

Amit D
Updated on 14-Feb-2020 10:12:54

111 Views

The insertAfter( selector ) method inserts all of the matched elements after another, specified, set of elements.Here is the description of all the parameters used by this method −selector − Content after which the selected element(s) is inserted.ExampleYou can try to run the following code to learn how to use jQuery.insertAfter() method in jQuery −Live Demo           jQuery insertAfter() method                              $(document).ready(function() {             $("div").click(function () {                $("#source").insertAfter(this);             });          });                              .div {             margin:10px;             padding:12px;             border:2px solid #666;             width:60px;          }                             Click on any square below to see the result:                                                

How to use jQuery.insertBefore() method in jQuery?

Amit D
Updated on 14-Feb-2020 10:08:34

230 Views

The insertBefore( selector ) method inserts all of the matched elements before another, specified, set of elements. Here is the description of all the parameters used by this method −selector − Content before which the selected element(s) is inserted.ExampleYou can try to run the following code to learn how to use jQuery.insertBefore() method in jQuery −Live Demo           jQuery insertBefore() method                              $(document).ready(function() {             $("div").click(function () {                $("#source").insertBefore(this);             });          });                              .div {              margin:10px;              padding:12px;              border:2px solid #666;              width:60px;          }                             Click on any square below to see the result:                                                

How to use jQuery.text() method in jQuery?

Amit D
Updated on 14-Feb-2020 10:04:19

81 Views

The text( ) method gets the combined text contents of all matched elements. This method works for both on XML and XHTML documents.ExampleYou can try to run the following code to learn how to use jQuery.text() method in jQuery −Live Demo           jQuery text() method                          $(document).ready(function() {             var content = $("p#pid1").text();             $("#pid2").html(content);          });                              .red {             color:red;          }          .green {             color:green;          }                         This is first paragraph.       This is second paragraph.        

How to use jQuery.wrapAll() method in jQuery?

Amit D
Updated on 14-Feb-2020 10:03:16

113 Views

The wrapAll() method wraps all the elements in the matched set into a single wrapper element.Here is the description of all the parameters used by this method −elem − A DOM element that will be wrapped around the target.ExampleYou can try to run the following code to learn how to use jQuery.wrapAll() method in jQuery −Live Demo           jQuery wrapAll() method                      $(document).ready(function() {            $('ul.myclass > li:lt(2)').wrapAll('')          });                      .demo {             border: 3px dashed blue;             margin: 5px;          }                                    India          US          UK          Australia          Bangladesh          

How to use jQuery.wrapInner() method in jQuery?

Amit D
Updated on 14-Feb-2020 10:01:07

71 Views

The wrapInner() method wraps the inner child contents of each matched element (including text nodes) with a DOM element.Here is the description of all the parameters used by this method −html − A DOM element that will be wrapped around the target.ExampleYou can try to run the following code to learn how to use jQuery.wrapInner() method in jQuery −Live Demo           jQuery wrapInner() method                              $(document).ready(function() {             $("div").click(function () {           ... Read More

How to wrap first few items in div using jQuery?

Amit D
Updated on 14-Feb-2020 08:21:33

536 Views

To wrap first few items in div, use the lt selector and to wrap, use the wrapAll() method. You can try to run the following code to learn how to wrap first few list items in div using jQuery −ExampleLive Demo           jQuery wrap() method                      $(document).ready(function() {            $('ul.myclass > li:lt(4)').wrapAll('')          });                      .demo {            border: 3px dashed blue;            margin: 5px;          }                                    India          US          UK          Australia          Bangladesh          Nepal          Bhutan          

Advertisements