Simple Filter HTML Tag in jquery

filter

filter is used to get specified element.

jQuery Example Code - To Filter HTML Tag using class attribute

<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:
html paragraph element filters code output

This jQuery code is used to filter the paragraph elements with class name 'high' and applies the style color as blue.

jQuery Example Code - To Filter HTML Tag using id attribute

<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.

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^