How do I use JQuery to do this? (Loop through the classes)

Posted by alex on Stack Overflow See other posts from Stack Overflow or by alex
Published on 2010-03-20T00:05:58Z Indexed on 2010/03/20 0:11 UTC
Read the original article Hit count: 98

Filed under:
|

Suppose my code is like this:

<td class="apple">
<div class="worm">
text1
</div>
</td>

<td class="apple">
<div class="worm">
text2
</div>
</td>

<td class="apple">
<div class="worm">
text3
</div>
</td>

How can I loop through everything with "tr class apple", and then grab the text of the div inside with id "worm", and then set each of the .attr() as that text?

Result:

<td class="apple" title="text1">
<div class="worm">
text1
</div>
</td>

<td class="apple" title="text2" >
<div class="worm">
text2
</div>
</td>

<td class="apple" title="text3">
<div class="worm">
text3
</div>
</td>

Thank you

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript