jquery - Add a div class parent to img and iframes with exception for blockquotes -
i'm using these jquery snippets:
$(".post img").each(function(){ $(this).wrap('<div class="fwparent" />'); }); $(".post iframe").each(function(){ $(this).wrap('<div class="fwparent" />'); });
to wrap images , iframes fwparent div class. need them make exceptions blockquotes.
it looks now:
<div class="post"> ... <div class="fwparent"><img src="image.png"></div> <div class="fwparent"><iframe src="movie"></div> ... <blockquote> <div class="fwparent"><img src="image.png"></div> <div class="fwparent"><iframe src="movie"></div> </blockquote> ... </div>
but want this:
<div class="post"> ... <div class="fwparent"><img src="image.png"></div> <div class="fwparent"><iframe src="movie"></div> ... <blockquote> <img src="image.png"> <iframe src="movie"> </blockquote> ... </div>
does know how achieve this?
you can try code rather :
$(".post img, .post iframe").each(function(){ if ($(this).parent().prop('tagname') != 'blockquote') { $(this).wrap('<div class="fwparent" />'); } });
the code checks if parent of current element blockquote, , if it's not, wrap element. code uses prop method.
Comments
Post a Comment