Guest User

Untitled

a guest
Aug 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. Append content on random location with jQuery?
  2. <ul class="itemlist">
  3. <li>Item #2</li>
  4. <li>Item #2</li>
  5. <li>Item #3</li>
  6. <li>Item #4</li>
  7. </ul>
  8.  
  9. .itemlist li{
  10. width:100px;
  11. height: 100px;
  12. margin: 8px;
  13. padding: 4px;
  14. float: left;
  15. background: #dddddd;
  16. }
  17.  
  18. var $lis = $(".itemlist li");
  19. $lis.eq(Math.floor(Math.random()*$lis.length)).after(
  20. /* your new content here */ );
  21.  
  22. var randomNum = Math.floor(Math.random()*9);
  23. $(".itemlist li").eq(randomNum).append("HI");
Add Comment
Please, Sign In to add comment