JQuery "contains" returns nothing for html coding

var foundin = $('*:contains("the")').last();

works on the page but

var foundin = $('*:contains("&copy")').last();

returns nothing even if '& copy' appears in the page source. I tried to avoid the "&", but that would not work either. Is there any way I use contains to find an HTML encoded character on a page?

Basically, I want to find an element containing & copy; and disassemble it to get the copyright holder. I asked a similar question related to this using regex: choose an HTML text element with regex?

+3
source share
1 answer

Quick and dirty:

var $div = $("<div>");

$.expr[":"].containsEnc = function(a, b, c, d) {
    var decoded = $div.html(c[3]).text(); // decode &copy to ©

    return ~a.textContent.indexOf(decoded); // does the element contain the character
};

containsEnc :

$('body:containsEnc("&copy")').html('ok');

.

http://jsfiddle.net/wfLur/1/

+1

All Articles