<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.
$(‘li[aaa=’ + this.id + ‘]’).addClass(‘back’);added to the inner part of your fiddle will do it. Updated based on comment from OP.