admin管理员组文章数量:1206765
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");
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");
Share
Improve this question
asked Apr 16, 2013 at 20:54
IljaIlja
46.5k103 gold badges289 silver badges525 bronze badges
1
- Seriously, this is about as basic as you can get. Why don't you give just a tiny bit of effort, visit the jQuery docs, type in "parent" and see what comes up. Is that really too hard for you? – user1106925 Commented Apr 16, 2013 at 21:30
5 Answers
Reset to default 10this.parent().removeClass("playing");
$(this).closest('div').removeClass("playing")
or
$(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>
本文标签: javascriptremove class from parent element with jQueryStack Overflow
版权声明:本文标题:javascript - remove class from parent element with jQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738689452a2107017.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论