Jquery Selector With Regex
I am looking to scan a page and look for any html elements that have a class or id that contains the word price. My thought was to use regex here but I cannot get it to fire correc
Solution 1:
"\b"
is same as "\x08"
.
Escape \
:
var price = $("div:regex(\\bprice\\b)").text();
Solution 2:
Solution 3:
You can do that by adding new pseuo selector:
jQuery.expr[':'].regex = function(elem, index, match) {
var regex = new RegExp(match[3]),
$elem = $(elem);
return regex.test($elem.attr('class')) || regex.test($elem.attr('id'));
};
and you can use this selector using:
$("div:regex(\\bprice\\b)")
Post a Comment for "Jquery Selector With Regex"