PDA

View Full Version : Jquery attr


PaulF
01-26-2010, 10:11 PM
Hi,

I need a little help with some jQuery, I need to wrap a number of images in <a> tags and add the src and alt attributes.

The code below works correctly, it wraps each <img> tag adds the src to the <a> tag as an href, however if I try and do the alt attribute it only moves the first word. e.g. alt="Eco Pod" -> title="Eco" Pod="" is the output.

I don't have much hair, and therefore any help would be greatly received.

$(document).ready(function() {
$("#gallery img").each(function(){
$(this).wrap("<a href=" +$(this).attr('src') + " >");
$(this).css("display", "none");
});
$("#gallery img:first").css("display", "");
});

<img src="../images/awards_logos/ECO_POD_Logo_RGB.jpg" alt="Eco Pod" />