I am trying to check if a td innertext contains parentheses (). The reason is I display negative numbers as (1000) and I need to convert them to -1000 to do math. I\'ve trie
I don't use jQuery much, but the problem with your first one is that you're trying to put in text where it should be a selector - then you tried using a selector ":contains", but you then tried to escape the "(". Have you tried $("#fscaTotals td").filter(":contains('(')")? Use contains, but don't try to escape the parentheses.
I think you'll have to use a filter function like:
$('#fscaTotals td *').filter(function(i, el) {
return !!$(el).text().match(/\(/);
});
Edit: I think this is a bug in jQuery's :contains()
.
You can add a RegEx filter
This technique is explained in this Blog Entry
$.extend($.expr[':'], {
regex: function(a, i, m, r) {
var r = new RegExp(m[3], 'i');
return r.test(jQuery(a).text());
}
});
Then you could use a regular expression like so.
("#fscaTotals td:regex('\([0-9]*\)')")
By the way, I tested the RegEx example above with RegexBuddy and I think it is correct for your needs.