I have this html code
<ul>
<li><a href="#"><img src="path_to_image1"><span>some text</span></a></li>
<li><a href="#"><img src="path_to_image2"><span>some text</span></a></li>
<li><a href="#"><img src="path_to_image3"><span>some text</span></a></li>
</ul>
Images are of different width.
I need to set width of SPAN element to be equal as IMG width.
Here is the code that I wrote by looking over the StackOverflow board.
$(document).ready(function() {
$("ul li a").each(function() {
var theWidth = $(this).find("img").width();
$("ul li a span").width(theWidth);
});
});
Now this code returns only width of the last image.
What to change so I can have width of span element same as img?
Thanks
the answer is in your own code, almost..