本文介绍了jQuery属性选择器或操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的 html :
<div id="l">l</div> <div id="a">a</div> <div id="i">i</div>
如何只改变 l 和 a 属性元素?我用OR搜索一个选择器,像这样:
How to change the color of only the l and a attributed elements? I searched for a selector with OR, something like this:
$(function(){ $('div[id=l,a]').css('color','red'); });
它不工作,在jQuery中有类似的东西吗?
It's not working, is there something like that in jQuery?
EDIT
谢谢你们现在的工作:
EDITThank you guys it's working now:
$('[id=l], [id=a]').css('color', 'red');
但是如果我想在< div> ; like $('[id = l],[id = a]','div')。这不行,我该怎么办?
But what if I want to search for those IDs inside a <div> like $('[id=l], [id=a]','div'). This doesn't work, how should I do it?
推荐答案
$(function(){ $('#l, #a').css('color','red'); });
小提琴:
这篇关于jQuery属性选择器或操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!