Select Elements Having Inner Element Matching selector .has("selector")

.has("selector")

selector: jQuery selector or DOM element
e.g. $("div").has("p")

.has("selector") selects elements in the matched set that have at least one inner element mathcing selector.

Example 1: $("div").has("p") will first find all <div> then select the ones that have at least one inner <p> element.

<div>
  <p>p1</p>
</div>

<div>
  <span>span</span>
</div>

<div>
  <p>p2</p>
</div>

jQuery traversing filtering .has("selector")