I am extremely new to jQuery and JS in general. I need a script to scan the page and replace any images classified as "rounded" with a div wrapper, so I can apply rounded corners via css3. The code I made works fine if there are more than 1 image on the page, it just returns the first image 3 times instead of 3 separate images.
Code below - any help is appreciated.
var imageWrap = jQuery("img.rounded").attr("src");
var imageWrapWidth = jQuery("img.rounded").attr("width");
var imageWrapHeight = jQuery("img.rounded").attr("height");
var imageWrapAlt = jQuery("img.rounded").attr("alt");
jQuery("img.rounded").wrap("<div class='image-wrapper'><p></p>" + "</div>");
jQuery(".image-wrapper").css({'background' : 'transparent url('+imageWrap+') no-repeat 0 0','width':imageWrapWidth,'height':imageWrapHeight} );
jQuery(".image-wrapper p").text(imageWrapAlt);
jQuery('img.rounded').hide();
source
share