如何从所有元素jQuery中删除类 [英] How to remove class from all elements jquery

查看:73
本文介绍了如何从所有元素jQuery中删除类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下内容更改元素的类

I am changing the class of an element with the following

  $("#"+data.id).addClass("highlight")

给出以下列表.

 <div id="menuItems"> 
 <ul id="contentLeft" class="edgetoedge"> 
 <li  class="sep" ">Shakes and Floats</li> 
 <li id="297"><a href="#" onClick="cart('297','add')"><small>$5.00</small><b>Vanilla</b>     </a></li> 
 <li id="298"><a href="#" onClick="cart('298','add')"><small>$5.00</small><b>Peanut Butter</b></a></li> 
 <li id="299"><a href="#" onClick="cart('299','add')"><small>$5.00</small><b>Combo</b></a></li> 
 <li id="300"><a href="#" onClick="cart('300','add')"><small>$5.00</small><b>Chocolate</b></a></li> 
 <li id="301"><a href="#" onClick="cart('301','add')"><small>$5.00</small><b>Strawberry</b></a></li> 
 <li id="303"><a href="#" onClick="cart('303','add')"><small>$5.00</small><b>Banana</b></a></li> 
 <li id="304"><a href="#" onClick="cart('304','add')"><small>$5.00</small><b>Root Beer Float</b></a></li> 
 <li id="305"><a href="#" onClick="cart('305','add')"><small>$5.00</small><b>Espresso</b></a></li> 
 </ul>
 </div> 

我以为我可以用这个删除班级...

I assumed I could remove the class with this...

  $(".edgetoedge").removeClass("highlight");

但这不起作用.如何删除课程?

But this doesn't work. How can I remove the class?

推荐答案

您需要选择.edgetoedge类中包含的li标记. .edgetoedge仅匹配一个ul标签:

You need to select the li tags contained within the .edgetoedge class. .edgetoedge only matches the one ul tag:

$(".edgetoedge li").removeClass("highlight");

这篇关于如何从所有元素jQuery中删除类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆