admin管理员组

文章数量:1201581

Here is my html:

<div id="l">l</div>
<div id="a">a</div>
<div id="i">i</div>

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');
});

It's not working, is there something like that in jQuery?

EDIT Thank you guys it's working now:

$('[id=l], [id=a]').css('color', 'red');

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?

Here is my html:

<div id="l">l</div>
<div id="a">a</div>
<div id="i">i</div>

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');
});

It's not working, is there something like that in jQuery?

EDIT Thank you guys it's working now:

$('[id=l], [id=a]').css('color', 'red');

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?

Share Improve this question edited Nov 4, 2015 at 18:02 Felipe Oriani 38.6k19 gold badges137 silver badges201 bronze badges asked Jun 27, 2011 at 19:27 trrrrrrmtrrrrrrm 11.8k25 gold badges87 silver badges131 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 23
$(function(){
    $('#l, #a').css('color','red');
});

Fiddle: http://jsfiddle.net/maniator/2Xuat/

本文标签: javascriptjQuery Attribute Selectors OR OperationStack Overflow