JQuery: How to apply css to a .wrap element?
- by Eamonn
My code thus far:
$(".lorem img:not(.full-img)").each(function() {
$(this).addClass("inline-img");
var imgWidth = $(this).prop('width');
var imgHeight = $(this).prop('height');
var imgFloat = $(this).prop('float');
$(this).wrap('<div class="inline-img-wrap" />');
if ($(this).prop("title")!='') {
$('<p class="inline-img-caption">').text($(this).prop('title')).insertAfter($(this));
}
});
I am searching for images within a body of text, appending their title values as captions underneath, and wrapping both img and p in a div.inline-img-wrap. That works fine.
What I need help with is applying the styling of the img to the new wrapping div instead. You can see I have created vars for just this, but cannot get applying them to work. $this will always apply to the image, and <div class="inline-img-wrap" style="width:'+imgWidth+'"> doesn't work.
All advice appreciated!