Jquery filter( selector) method:-
It is one of the most important method which we can use to filter out elements from a list of DOM elements.
It removes all elements from the set of matched elements that do not match the specified selector(s).
Syntax:- selector.filter( selector )
Example:-
<html>
<head>
<title>The jQuery Example</title>
<script type = "text/javascript"
src = "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
$("li").filter(".middle").addClass("selected");
});
</script>
<style>
.selected { color:yellow; }
</style>
</head>
<body>
<div>
<h4>Mobile</h4>
<ul>
<li>Apple</li>
<li>Sony</li>
<li>HTC</li>
<li>Samsung</li>
<li>LG</li>
<li>Motorola</li>
</ul>
</div>
</body>
</html>
0 Comment(s)