简体   繁体   中英

remove class from parent element with jQuery?

I can't figure out how to remove class from a parent element, basically I have a <audio> tag (from now on referred to as this ) which is inside a div with class="playing" how can I remove this class?

tried this, but than understood that it will remove class from audio element not it's parent div:

this.removeClass("playing");
this.parent().removeClass("playing");
$(this).closest('div').removeClass("playing")

要么

$(this).closest('div.playing').removeClass('playing')
this.closest('div[class=playing]').removeClass("playing");

JSfiddle Demo

<div class="bold">
<p id="p1" class="blue under">Hello</p>
</div>
<div class="bold">
  <p  id="p2" class="blue under highlight">and</p>
</div>
  <p class="blue under">then</p>
  <p class="blue under">Goodbye</p>


$("#p1").parent().removeClass("bold");

 $("input").keyup(function () { $(this).parent().removeClass('bg-red'); });
 .bg-red { background-color: red; }.h-50 { height: 50px; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="h-5 bg-red"> <h3>Add text inside input will remove "bg-red" class from parent div</h3> <input placeholder="Enter anything" type="text"> </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM