How can I count the matched classes with jQuery’s :contains?
If I have the following code :
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div class="ll">John Resig</div>
<div class="ll">George Martin</div>
<div>Malcom John Sinclair</div>
<div class="ll">J. Ohn</div>
<script>
$("div.ll").hide()
$("div.ll:contains('John')").show();
</script>
</body>
</html>
How do I count the matched elements?
Use
.size()orlengthAnd you should use
lengthbecause the docs say