Try .filter.
I found another question on SO with pertinent info:
http://stackoverflow.com/questions/345194/regular-expression-matching-in-jquery
Josh
2009-10-08 00:17:23
Try .filter.
I found another question on SO with pertinent info:
http://stackoverflow.com/questions/345194/regular-expression-matching-in-jquery
$('div:contains("£")').each( function() {
var text = $(this).html();
if (text && text.match(/\s*£\s*/)) {
$(this).addClass('pound');
}
});
I believe the problem is that the browser is transforming the HTML escape characters, so you need to look for the actual character... I tested this and it works
$(document).ready(function(){
$('div').each(function(){
if ($(this).html() == "£"){
$(this).addClass("pound");
}
})
})
tvanfosson's code allows for whitespace either side of the £ sign, but the regular expression could do with a bit of modification:
$('div:contains("£")').each( function() {
var text = $(this).html();
if (text && text.match(/^\s*£\s*$/)) {
$(this).addClass('pound');
}
});
note the '^' and '$' indicating the beginning and end of the string.