Custom User Selectors
In this chapter you will learn:
Custom Selectors
You can extend the core jQuery object. The following code snippet creates a custom selector that selects elements with a red background.
<!DOCTYPE html> <!--from ja v a2 s . c o m-->
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js">
</script>
<script>
$(function(){
$.expr[":"].redbg = function(element) {
return $(element).css("background-color") === "red";
};
var n = $(":redbg").length;
document.writeln(n);
});
</script>
</head>
<body>
<div style="width:10; height:10; background-color:green;"></div>
<div style="width:10; height:10; background-color:red;"></div>
<div style="width:10; height:10; background-color:blue;"></div>
</body>
</html>
Next chapter...
What you will learn in the next chapter: