Home > front end >  Check if element text is `&ndash`
Check if element text is `&ndash`

Time:11-03

I want to check if selected element contains n-dash only:

<p>&ndash;</p>

But jQuery does not compare it this way:

$('p').text()=="-"
$('p').html()=="-"
$('p').text()=="&ndash;"
$('p').html()=="&ndash;"

All above is false.

CodePudding user response:

https://api.jquery.com/contains-selector/

https://www.fileformat.info/info/unicode/category/Pd/list.htm

let selector = $('p:contains("\u2013")');

if (selector.length) {
  console.log('got it !');
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>&ndash;</p>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related