How to Remove Contents of an Element (div, ul, etc) with jQuery

Hello,

As I’ve been recently working with a website that has a lot of jQuery and AJAX, and my jQuery knowledge was small, I was wondering how to remove the content of a <div> with jQuery. The solution was pretty easy and with just a line of code.

The element we are going to affect will be called ‘Target’.

1. Set the id of the Target to ‘ourtargetid’ (for example).

<div id='ourtargetid'></div>

2. In the <head> section of your document, wrapped between JavaScript tags, you will use the function remove().

$(element).remove();

So for your div we will use:

$('#ourtargetid').remove();

Easy as that. Now if you would like to remove something by its class attribute, we would use:

$('.classname').remove();

And that’s it. It is really simple, yet very useful when you want to remove an element dynamically. If you have any question, please do not hesitate to contact me.

Best Regards,

Richi

Owner of Juapo2Services

Looking for quality Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , | Posted under Programming/Coding | RSS 2.0

Author Spotlight

Richi González

Richi González

I started programming when I was 12. I'm a Developer and have been working with the Clip-Bucket script since it came out. I'm the Liaison between Arvixe and Clip-Bucket, so anything you need regarding Clip-Bucket or any particular computer-related subject you need, let me know so I can assist you.

Leave a Reply

Your email address will not be published. Required fields are marked *


1 × 8 =

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>