trevoray
trevoray

Reputation: 317

remove specific classes within a div

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");

Upvotes: 4

Views: 14667

Answers (3)

Jacob
Jacob

Reputation: 383

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>

Upvotes: 0

War10ck
War10ck

Reputation: 12508

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()

Upvotes: 4

Jay Blanchard
Jay Blanchard

Reputation: 34416

Do this -

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

Upvotes: 2

Related Questions