jQuery - has()

The has() selector selects all elements that have one or more elements inside of them, that matches the specified selector.

has() selects elements with other elements within them. contains finds elements with simple text-based matches.

This is a span element inside a p element.

This is a p element with no span element.

$("p:has(span)").css("border", "solid red");