javascript 使用 jQuery 从父元素中删除类?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16046879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
remove class from parent element with jQuery?
提问by Ilja
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?
我不知道如何从父元素中删除类,基本上我有一个<audio>
标签(从现在开始称为this
),它位于 div 内,class="playing"
如何删除此类?
tried this, but than understood that it will remove class from audio element not it's parent div:
试过这个,但比理解它会从音频元素中删除类而不是它的父div:
this.removeClass("playing");
回答by Uncle Iroh
this.parent().removeClass("playing");
回答by Schleis
$(this).closest('div').removeClass("playing")
or
或者
$(this).closest('div.playing').removeClass('playing')
回答by Mohammad Adil
this.closest('div[class=playing]').removeClass("playing");