Reputation: 21
<select id="list" multiple=multiple>
<option value="1" id="one" selected="selected">one </option>
<option value="2" id="two" selected="selected">two </option>
<option value="3" id="three">three </option>
</select>
<ul id="uli">
<li aaa="one">one</li>
<li aaa="two">two</li>
<li aaa="three">three</li>
</ul>
With the CSS:
.back {
color: red;
}
And the Javascript:
$("#list").find("option:selected").each(function() {
// logic here
});
Into the each()
callback, I want to add class for equivalent in uli. I would like to use addClass(.back)
for li where attr aaa
== id
for list.
live: http://jsfiddle.net/yjL9n/3/
Upvotes: 1
Views: 405
Reputation: 43823
$('li[aaa=' + this.id + ']').addClass('back');
$('table').find('td[aaa="'+this.id+'"]').addClass('back');
added to the inner part of your fiddle will do it. Updated based on comment from OP.
Upvotes: 1
Reputation: 5229
Here you go:
$("#uli").find('[aaa="'+this.id+'"]')
.addClass('back');
Upvotes: 7
Reputation: 35793
This works (and is tidier):
$("#list option:selected").each(function() {
$('#uli li[aaa="' + this.id + '"]').addClass('back');
});
However I wouldn't use aaa as an attribute!
Upvotes: 2
Reputation: 69905
Try this
$("#list").find("option:selected").each(function() {
$("#uli").find('[aaa="'+this.id+'"]').addClass('back');
});
Upvotes: 1