Advertisement
cdsatrian

insertBefore

Jul 3rd, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function appendNewText()
  5. {
  6. var nums = Math.floor(Math.random()*1000);
  7.  
  8. var newText = document.getElementById('getNamaKota').value;
  9.  
  10. var newlist="<li id='"+nums+"'>"+newText + "&nbsp;<a href=\"#\" onclick=hapus("+nums+")>Hapus</a></li>";
  11.  
  12. var para = document.getElementById("list-nama-kota").innerHTML;
  13.  document.getElementById("list-nama-kota").innerHTML=newlist+para;
  14. }
  15.  
  16. function hapus(id)
  17. {
  18. document.getElementById(id).style.display = "none";
  19. }
  20. </script>
  21. </head>
  22. <body>
  23.  
  24. <input type="text" id="getNamaKota"><input type="button" value="append Text" onclick="appendNewText()"/>
  25. <ul id='list-nama-kota'>
  26. </ul>
  27.  
  28. </body>
  29. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement