Jquery filter () method
The filter () method in jquery allows you to define a filter rule. elements that do not match this standard will be deleted from the set, and matched elements will be returned. 1. filter () syntax $ (selector). filter (criteria, function (index) parameter description criteria is optional. Specifies the selector expression, jQuery object, and one or more elements to be returned from the selected element combination. Tip: To specify multiple conditions, use commas to separate them. Function (index) is optional. Specifies the function to be run for each element in the set. If true is returned, the elements are retained; otherwise, the elements are removed. Index-the index position of the element in the set. Note: this is the current DOM element. Ii. filter () instance in jquery
<Ul> <li> list item 1 </li> <li> list item 2 </li> <li> list item 3 </li> <li> list item 4 </li> <li> list item 5 </li> <li> list item 6 </li> </ul> <script >$ ('lil '). filter (': even').css ('background-color', 'red'); </script>