JQuery each element to set color - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:each

Description

JQuery each element to set color

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*w w  w  .j a va2s .c  o  m*/
var one = $("p").each(function() {
   $(this).css("color", "green");
});
var two = $.each( $("p"), function() {
   $(this).css("color", "green");
});
$('span').html(one.length + '<br/>' + two.length);
    });

      </script> 
 </head> 
 <body> 
  <p>1</p> 
  <p>2</p> 
  <span></span>  
 </body>
</html>

Related Tutorials