-
Notifications
You must be signed in to change notification settings - Fork 52
/
sample033.html
22 lines (21 loc) · 1.04 KB
/
sample033.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!DOCTYPE html>
<html lang="en">
<body>
<div id="123"></div>
<div id="oneTwoThree"></div>
<div id="0"></div>
<div id="zero"><div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script> (function ($) {
//James Padolsey filter extension
jQuery.expr[':'].regex = function (elem, index, match) {
var matchParams = match[3].split(','), validLabels = /^(data|css):/, attr = { method: matchParams[0].match(validLabels) ? matchParams[0].split(':')[0] : 'attr', property: matchParams.shift().replace(validLabels, '') }, regexFlags = 'ig', regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g, ''), regexFlags);
return regex.test(jQuery(elem)[attr.method](attr.property));
}
// Select div's where the id attribute contains numbers
alert($('div:regex(id,[0-9])').length); // Alerts "2"
// Select div's where the id attribute contains the string "Two"
alert($('div:regex(id, Two)').length); // Alerts "1"
})(jQuery); </script>
</body>
</html>