js遍历一个div下的所有一个特定的标签

来源:互联网 发布:新日铁住金软件 薪资 编辑:程序博客网 时间:2024/05/29 08:33
<div id="colors" class="pre spec"><c:forEach items="${colors}" var="color"><a onclick="colorToRed(this)" href="javascript:void(0)" title="西瓜红" class="changToRed"><img width="25" height="25" data-img="1" src="/res/img/pic/ppp00.jpg" alt="西瓜红 "><i>${color.name }</i></a></c:forEach></div>

遍历id为colors里面的所有标签为a的标签

<pre name="code" class="javascript">function colorToRed(target){//先清理$("#colors a").each(function(){$(this).attr("class","changToWhite");});$(target).attr("class","changToRed"); }




0 0
原创粉丝点击