X

LATEST #JQUERY NEWS

jQuery’s .remove() Method


Ever wanted to remove an HTML element from your code dynamically? There are many situations in which being able to do this easily would be useful, and with jQuery, it’s completely doable using the .remove() method.

Here’s how it works. Let’s say you want to remove a div (.bye) when it’s clicked on. The following could would execute that action:

$(".bye").click(function(){
   $(this).remove();
})

You can also use the method to remove all elements of a particular tag type, and then use the parentheses to pass certain parameters through so that only HTML elements of a particular tag type AND a particular class or ID will be removed. So for example, let’s say that when .bye is clicked, you’d like to remove all <p> tags with a class of .delete-me. Here’s how that cod should look.

$(".bye").click(function(){
   $("p").remove(".delete-me");
})

Don’t forget that using the .remove() method will remove your selected element AND everything inside of it, so make sure to exercise caution so you don’t accidentally delete anything you don’t mean to.

Recently Published

article image
»

7 Responsive jQuery Dropdown Menu Plugins

Dropdown Menu Plugins Dropdown menus are mostly used for website ...

article image
»

20 Stylish and Modern jQuery Tooltip Plugins

jQuery Tooltip Plugins Tooltips are a great option for showing extra ...

article image
»

15 Newest jQuery plugins for responsive website

Due to the proliferation of smartphones and tablets, responsive ...

article image
»

How to use Redux with jQuery

State management is one of most integral parts of any software and a ...

article image
»

Fade HTML Table Row on Hover Using jQuery

HTML tables are the ideal choice for displaying data in tabular form. ...

article image
»

Drag and Drop HTML Table Rows Using jQuery

HTML tables are the preferred UI option for displaying data. Sorting, ...

article image
»

Top 5 Best JavaScript Template Engines

Template engines help in the decoupling of HTML and JavaScript code ...

article image
»

3 jQuery/JavaScript Plugins for Push Notifications

Push notifications started from the mobile business but this ...

article image
»

Create Smooth Animation Using jQuery’s “stop()”

Making Quick Work jQuery’s animate() method is a quick way to ...