View Single Post
Old 08-15-2009, 05:04 PM   PM User | #1
lauthiamkok
Regular Coder

 
Join Date: Dec 2008
Posts: 117
Thanks: 14
Thanked 0 Times in 0 Posts
lauthiamkok is an unknown quantity at this point
jquery: creating image caption from alt

hi,
I am trying to create image caption by getting the value from alt in each img tag. i manage to get the alt value from each img tag with each();.

and i use insertAfter() to insert the alt value after each image, but it turns out very strange, have a look from the link below,

http://lauthiamkok.net/tmp/jquery/jquery.image_caption/

it create a list of captions instead!

what have done wrong to make this image caption function?

this is the code i made so far,

Code:
$("#content img").each(function () {
	var title = $(this).attr("alt");
	$(document.body).append("<div class='caption'>"+ title +"</div>");	
	$(".caption").insertAfter("#content img");
	});
});
many thanks if u have any idea.

thanks,
Lau
lauthiamkok is offline   Reply With Quote