I want to add a class to only those <p>
elements that have an <img>
.
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.
$(".entry-content p img").parent("p").addClass("no-orphans-ctnr");
Either would seem to be off-topic for Code Review: questions about code not yet written. \$\endgroup\$