$(selector).filter(selector)
$(selector).filter(function(index))
filter("id1, #id2")
<!DOCTYPE html>
<html>
<head>
<style>
div{
font-size: 20px;
font-weight: bold;
}
</style>
<script src="/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function fun(){
$(document).ready(function(){
$("p").filter(".para").css({"background": "yellow"});
});
}
</script>
</head>
<body>
<h2> Welcome to the bianchenghao6.com </h2>
<h4>This is an example of using the jQuery's filter() method. </h4>
<div id = "div1"> This is first div element. </div>
<p class = "para"> This is first paragraph element </p>
<div id = "div2"> This is second div element. </div>
<p class = "para"> This is second paragraph element </p>
<p class = "para"> This is third paragraph element </p>
<p> Click the following button to see the effect. </p>
<button onclick = "fun()"> click me </button>
</body>
</html>
Welcome to the bianchenghao6.com
This is an example of using the jQuery's filter() method.
This is first paragraph element
This is second paragraph element
This is third paragraph element
Click the following button to see the effect.
<!DOCTYPE html>
<html>
<head>
<style>
p{
font-size: 20px;
font-weight: bold;
}
</style>
<script src="/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function fun(){
$(document).ready(function(){
$("p").filter(function(index) {
if(index == 1 || index == 3 || index == 5){
return true;
}
}).css({"background": "yellow"});
});
}
</script>
</head>
<body>
<h2> Welcome to the bianchenghao6.com </h2>
<h4> This is an example of using the jQuery's filter() method. </h4>
<p class = "para1"> P1 </p>
<p class = "para2"> P2 </p>
<p class = "para3"> P3 </p>
<p class = "para4"> P4 </p>
<p class = "para5"> P5</p>
<p class = "para6"> P6 Click the following button to see the effect. </p>
<button onclick = "fun()"> click me </button>
</body>
</html>
Welcome to the bianchenghao6.com
This is an example of using the jQuery's filter() method.
P1
P2
P3
P4
P5
P6 Click the following button to see the effect.