Add a class to an element when it's loaded I want to add a class to only those &lt;p&gt; elements that have an &lt;img&gt;.
So far this is what I have, it works, but I don't think I'm doing it right.

$(".entry-content p img").addClass(function(){
    $(this).parent("p").addClass("no-orphans-ctnr");
});


Here's a Demo/fiddle.

As you can see, I used the .addClass() method twice. I'm not a jQuery/JavaScript developer but that doesn't look right to me.
Please review and help me improve it.
To select the p elements that have an img as child element,
you can use the p:has(&gt; img) selector, like this:

$(".entry-content p:has(&gt; img)").addClass("no-orphans-ctnr");