JQuery add count to class - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:addClass

Description

JQuery add count to class

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.9.1.js"></script> 
  <style id="compiled-css" type="text/css">

div.selected {//ww w  . j  a  va  2  s.c  om
   background: red;
}
      </style> 
  <script type="text/javascript">
    $(window).load(function(){
$("div[class^='item']").addClass('selected');
    });

      </script> 
 </head> 
 <body> 
  <div class="item1">
    1 
  </div> 
  <div class="item2">
    2 
  </div>  
 </body>
</html>

Related Tutorials