-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery-custom-selector.html
46 lines (36 loc) · 1.01 KB
/
jquery-custom-selector.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<ul>
<li>
First "li" with content
</li>
<li>
</li>
<li>
Second "li" with content
</li>
<li>
</li>
</ul>
<script>
// $.expr[':'] Is the object that contains the selector functions.
//objNode: DOM node.
//intStackIndex: Dom node index.
//arrProperties: Properties of the selector used.
// arrNodeStack: The array of results of the selection
// It creates a new function in the object, that will be the selector. This function has to return true or false
$.expr[':'].emptyContent = function(objNode, intStackIndex, arrProperties, arrNodeStack) {
var node = $(objNode);
if(node.html().trim() == '') {
node.html('This element was empty. Now its filled by the example selector');
return true;
}
return false;
};
$('li:emptyContent').css('color', 'red');
</script>
</body>
</html>