jQuery Tutorial
filter is used to get specified element.
<html> <head> <title>The jQuery Example - To filter paragraph element</title> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script type = "text/javascript"> $(function(){ $("p").filter(".high").css("color", "blue"); }); </script> </head> <body> <p class="high">line 0</p> <p>line 1</p> <p>line 2</p> <p>line 3</p> <p class= "high">line 4</p> <p>line 5</p> <p class="high">line 6</p> </body> </html>Output:
This jQuery code is used to filter the paragraph elements with class name 'high' and applies the style color as blue.
<html> <head> <title>The jQuery Example - To filter paragraph element</title> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script type = "text/javascript"> $(function(){ $("p").filter("#high").css("color", "blue"); }); </script> </head> <body> <p id="high">line 0</p> <p>line 1</p> <p>line 2</p> <p>line 3</p> <p id= "high">line 4</p> <p>line 5</p> <p id="high">line 6</p> </body> </html>
This jQuery code is used to filter the paragraph elements with id attribute 'high' and applies the style color as blue.
Similarly any attribute can be used, or any custom function also be used with filter to filter the required elements.
« Previous Next »jQuery Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page