I know its sounds a bit crazy, but im doing some pretty complex (complex for me, not for better JS coder) WordPress theme and text in articles expands on hover,and post images shows in different div, and other stuffs. Anyhow I need a function that will check every post (article) and if post have img in it to put that img in other div, if not, live it as it is. I was never good at if else statements, I tried something but it didn’t helped.
var picture = $('.post p').find('img');
$(this).find('.postimage').empty().append(picture);
This worked as a test, but of course it appends image from first post to all “postimage” divs, and its not a wanted solution.
Use the
.each()method to operate on each matched item individually.e.g.