I am trying to get the values of an element and then use it in another element within the same parent element using .each()
function. However, this seems not to work. Here are the codes I am using. Please tell me where I am doing wrong.
HTML:
<table>
<tr class="item">
<td>
<img class="thumbnail" src="http://www.domain.com/images/image1.jpg">
</td>
<td>
<p class="img">http://www.domain.com/images/image001.jpg</p>
</td>
</tr>
<tr class="item">
<td>
<img class="thumbnail" src="http://www.domain.com/images/image2.jpg">
</td>
<td>
<p class="img">http://www.domain.com/images/image002.jpg</p>
</td>
</tr>
</table>
JavaScript:
<script type="text/javascript">
$(document).ready(function() {
$('.item').each(function() {
$(this).find('.thumbnail').attr('src', $(this).find('.img').html());
)};
)};
</script>
What I want to do is get the html of the <p class="img">
(which contains the url to an image) and change the src
of <img class="thumbnail">
with that on page load.
Please help