Hi all. I've just started using jQuery a couple of days ago. The first thing I've tried experimenting with is a wee bit of code that pulls the alt attribute value out of a certain class of image, wraps the image in a div, sets the div width to match the image and appends the alt text inside the div. I've got the following so far:
$(document).ready(function(){ $("img.caption").each(function(i) { var imgwidth = $(this).width(); var captiontext = $(this).attr("alt") $(this).wrap("<div class='captionborder'></div>"); $(this).parent().width(imgwidth); $(this).parent().append("<div>" + captiontext + "</div>"); }); }); The problem I have is that on the first load of the page in Firefox the width of the wrapping div is being set to zero. Refreshing the page results in the div expanding to the expected size. IE7 is not affected. Could anyone give me an idea as to what I'm doing wrong here?