Javascript label div classes numerically - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:addClass

Description

Javascript label div classes numerically

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.11.0.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//from  ww w.j  a  va2s  . c  o m
$('#main > div').addClass(function (i, clazz) {
    return '' + (i + 1)
})
    });

      </script> 
 </head> 
 <body> 
  <div id="main"> 
   <div>
     1 
   </div> 
   <div>
     2 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials