Displaying random number in LI - Javascript jQuery

Javascript examples for jQuery:List

Description

Displaying random number in LI

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <script src="https://code.jquery.com/jquery-1.4.2.min.js"></script> 
  <script>
        $(document).ready(function(){
            var len = $("ul.contentBlock li").length;
            $("ul.contentBlock li").each(function(){
                $(this).html(Math.floor(Math.random() * len));
            });//from w w w. j  av a2  s  . co m
        });
    
      </script> 
 </head> 
 <body> 
  <ul class="contentBlock"> 
   <li></li> 
   <li></li> 
   <li></li> 
   <li></li> 
  </ul>  
 </body>
</html>

Related Tutorials