JQuery: How to apply css to a .wrap element?

Posted by Eamonn on Stack Overflow See other posts from Stack Overflow or by Eamonn
Published on 2012-06-30T14:32:46Z Indexed on 2012/06/30 15:16 UTC
Read the original article Hit count: 196

Filed under:
|

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!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-selectors