There is a :contains
selector:
if ( $('span:contains("Example4")').length > 0 ) { ... }
However this approach will fail if there are <span>
elements with text like "Example 40"
. For strict comparison you may use trick with a .filter
method:
if ( $('span').filter(function() {
return $.trim($.text(this)) === 'Example4';
}).length > 0 ) { ... }