Reputation: 193
var foundin = $('*:contains("the")').last();
works on a page, but
var foundin = $('*:contains("©")').last();
returns nothing, even though '©' does appear in the page source. I tried escaping the '&', but that doesn't work either. Is there a way to use contains to find an html encoded character in a page?
Basically, what I want to do is find the element contains © and parse it to get the copyright holder. I asked a similar question aiming at this with regex here: select HTML text element with regex?
Upvotes: 3
Views: 281
Reputation: 154908
The quick and dirty:
var $div = $("<div>");
$.expr[":"].containsEnc = function(a, b, c, d) {
var decoded = $div.html(c[3]).text(); // decode © to ©
return ~a.textContent.indexOf(decoded); // does the element contain the character
};
Then you can use containsEnc
as a selector:
$('body:containsEnc("©")').html('ok');
It may not be the safest and most performant, though.
Upvotes: 1