jQuery attr()

The jQuery attr() method sets or returns the value of a property of selected elements. Syntax: When used to return an attribute’s value: $(selector).attr(attribute) When used to set an attribute and value: $(selector).attr(attribute,value) When used to set an attribute and value by using a function: $(selector).attr(attribute,function(index,currentvalue)) When used to set multiple attributes and values: $(selector).attr({attribute:value, … Read more

jQuery detach()

The jQuery remove() method removes the elements as well as its data and events. While the jQuery empty() method removes only the content from the selected elements. The jQuery detach() method is also used to serve the purpose of removal. The feature that makes this method unique from the rest two is that, this method … Read more

jQuery empty()

The jQuery empty() method removes only the child elements of the selected element. Syntax: $(selector).empty() Example1: <!DOCTYPE html> <html> <head> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script> <script> $(document).ready(function(){ $(“button”).click(function(){ $(“#div1″).empty(); }); }); </script> </head> <body> <div id=”div1″ style=”height:100px;width:200px;border:1px solid black;background-color:cyan;”> Hello! </div> <br> <button>Empty the div element</button> </body> </html> Example2: <!DOCTYPE html> <html> <head> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script> <script> $(document).ready(function(){ $(“button”).click(function(){ … Read more

jQuery remove()

jQuery provides two methods to remove HTML elements and content: remove() empty() The jQuery remove() method removes the selected elements and their child elements from the DOM. Removal of more than one element is also possible with the jQuery remove() method. All the elements should be separated with a comma (,) for the removal of … Read more

jQuery clone()

The jQuery clone() method is used to duplicate elements on a page, to make copies of the selected elements. Syntax: $(selector).clone(true) $(selector).clone(false) True: True parameter is used to specify that the event handler should also be copied. False: The false parameter is the default parameter of the clone() method which specifies that the event handler … Read more

jQuery append()

The jQuery append() inserts content at the end of the selected elements. Syntax: $(selector).append(content,function(index,html)) Content: Content is a compulsory parameter of the jQuery append() method, as it specifies the content to insert at the end of the selected element. It can accept the following values: HTML elements, jQuery objects, and DOM elements. Function: It is … Read more

jQuery after()

jQuery after() method is used to insert the specified content after each element in the set of matched elements. jQuery after() inserts content after the selected elements. Syntax: $(selector).after(content, function(index)) Content: Content is a compulsory parameter of jQuery after() method, as it specifies the content to insert after the selected element. It can accept the … Read more