<table>
<tr>
<td>aaa</td>
<td>aaa</td>
<td>
<div title="now">
<div id="here">here</div>
</div>
</td>
<td>
<div>vvvv</div>
</td>
<td>
<div>vvvv</div>
</td>
<td>
<div title="now">vvvv</div>
</td>
<td>
<div title="now">vvvv</div>
</td>
</tr>
</table>
I am in #here. I would like add class from this place all div with title="now". I want use find or others, but i can’t set this as $('div[title=now]').
$(#here).parent().parent().find(????).addClass('new');
I’ve used
closesthere to find the first parent which is atr, this is a little nicer than callingparenttwice. Thefindis just as you wrote.It’s not particularly clear whether you want all three things with title=now selected or not, but you should be able to work it out from this!
Should do the job. Here’s a fiddle showing what’s going on. http://jsfiddle.net/MurwG/3/
(By the way, closest is quicker than parents as demonstrated here: http://jsperf.com/jquery-parents-vs-closest/8)