Problems adding HTML .before .after an img with JQuery - JQuery closing tags -
alright, trying close img within (i know, know... not template) using jquery. happening - jquery closing tag adding .before... don't want closed until .after adding... struggling this. appreciated. i've tried .prepend/.append, , .wrap...
here code...
$(document).ready(function(){ $("img.bottomshadow").each(function(){ var imagewidth = $(this).attr("width"); var width = imagewidth + 10; $(this).before("<span class='image_shadow_container'>"); $(this).after("<img class='noimgbg' alt='' src='images/image_shadow.png' width='" + width + "'></span>"); });
});
what want is this:
<span class="image_shadow_container"> <img src="images/fwidth_img_3.jpg" class="image_shadow" alt="" /> <img src="images/image_shadow.png" alt="" width="300" class="noimgbg" /> </span>
what this...
<span class="image_shadow_container"></span> <img class="bottomshadow" width="160" height="128" alt="" src="images/newsimages/smallben.jpg"> <img class="noimgbg" width="170" src="images/image_shadow.png" alt="">
with span being closed "early" jquery... ideas?
you have .wrap()
, not use .before()
, jquery parses , corrects unclosed tags:
$("img.bottomshadow").each(function(){ var imagewidth = $(this).attr("width"); var width = imagewidth + 10; $(this).wrap("<span class='image_shadow_container' />"); $(this).after("<img class='noimgbg' alt='' src='images/image_shadow.png' width='" + width + "'></span>"); });
Comments
Post a Comment