Patrick Gregorio Patrick Gregorio - 4 months ago 9
jQuery Question

Use Jquery to select divs that have html entities

I need to select all

divs
that contain
<sup>
.

I already tried

var size = $("div:contains('<sup>')").length;


With the code above I get a length of
0
.

Sample HTML



<div>I have a &lt;sup&gt;superscript&lt;/sup&gt;!</div>

Answer

:contains() already escapes the entities for you.

var size = $("div:contains('<sup>')").length;
console.log(size);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>I have a &lt;sup&gt;superscript&lt;/sup&gt;!</div>