4

I'm trying to remove all specific classes within a specific div. I've tried various jQuery code and cannot get it working. I want to remove "remove all of this" below

<div id="commRollover">

<div class='nRegions' style='display:none;' id='Belgium' ><b><em>Belgium</em></b><BR><BR>                                                    

<div class='commIntro'>remove all of this</div>
<BR /></div>
<BR /></div>

I tried the following:

$("#commRollover").removeClass("commIntro");
1
  • You want to remove the div itself, or the class from the div? Commented Apr 30, 2014 at 19:28

3 Answers 3

4

Not sure whether you want to remove the class from the <div> or the <div> with the specified class. Both solutions are outlined below:

Remove the class from the div:

$('#commRollover .commIntro').removeClass('commIntro');

Documentation: .removeClass()

Remove the div with a specific class:

$('#commRollover .commIntro').remove();

Documentation: .remove()

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome thanks! I didn't realize I wasn't asking question correctly. I wanted to remove all divs with a specific class, so the second option worked great!
2

Do this -

$("#commRollover").find('.commIntro').remove(); // removes the entire div

Comments

0

The "removeClass" function will remove the class "commIntro" from the DIV, effectively resulting in HTML that looks like this:

<div class=''>remove all of this</div>

If what you actually want to do is remove the text "remove all of this" from the page, as you stated in your question, then try this:

$('.commIntro').html('');

Which will effectively result in HTML that looks like this:

<div class='commIntro'></div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.