简体   繁体   English

如何使用jQuery查找具有特定类的所有div元素

[英]How to find all div elements with specific class using jquery

In my JSP I have 3 div elements out of which 2 elements has class "shadow". 在我的JSP中,我有3个div元素,其中2个元素具有“ shadow” class

<div name="master" class="shadow">
..................................
</div>
<div name="child1" class="shadow">
..................................
</div>
<div name="child2" class="normalshadow">
..................................
</div>

Now in my java script, I want to find all the div elements which has class shadow and remove that class from those div elements. 现在,在我的Java脚本中,我想找到所有具有类shadow的div元素,并从这些div元素中删除该类。 How can i do that ? 我怎样才能做到这一点 ?

Find all div with class shadow using . 使用查找所有带有class shadow div . $(".shadow") and remove class use .removeClass() function please find below snippet for more info $(".shadow")并使用.removeClass()函数删除类,请在下面的代码段中查找更多信息

 $('div.shadow').removeClass('shadow'); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div name="master" class="shadow"> .................................. </div> <div name="child1" class="shadow"> .................................. </div> <div name="child2" class="normalshadow"> .................................. </div> 

$('div[class="shadow"]').removeClass("shadow")

如果要同时选择<div class="shadow"></div><div class="normalshadow"> ,则可以执行此$('div[class*=shadow]')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery查找具有特定类的所有元素 - jQuery find all elements with specific class 是否可以使用jquery定位调用事件的按钮的父div内特定类的所有元素? - Is it possible, using jquery, to target all elements of a specific class within the parent div of the button that calls the event? 如何找到jQuery中没有特定CSS类的所有元素? - How to find all elements that DON'T have specific CSS class in jQuery? 我如何使用 jQuery 删除除特定 class 之外的所有 div 和其他 DOM HTML 元素 - How can i remove all div's and other DOM HTML elements except a particular class using jQuery 使用javascript / jquery完全删除具有特定类的div的所有实例? - Completely delete all instances of a div with a specific class using javascript/jquery? 使用JQuery选择所有 <tr> 具有特定类的元素 - Using JQuery to select all <tr> elements with a specific class jQuery获取特定div下的所有元素 - jQuery get all elements beneath specific div 如何使用jquery查找并选择具有以特定单词开头的数据属性的所有元素? - How can I find and select all elements which have data attribute start with specific word with using jquery? 如何在类中查找div的元素 - How find a elements of div with class 如何使用JQuery为具有特定类的所有div分配唯一ID - How can I assign a unique ID to all div's that have a specific class using JQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM