Advertisement
kura2yamato

jquery - adding html

Mar 8th, 2025
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.00 KB | Source Code | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <script src="assets/jquery-3.7.1.js"></script>
  5.     <script src="assets/jquery-1.12.4.min.js"></script>
  6.     <script>
  7.       var jq112 = $.noConflict();
  8.     </script>
  9.     <style>
  10.     #str1, #str2{
  11.         margin-bottom:10px;border:1px solid black;padding:5px;
  12.     }
  13.     </style>
  14.   </head>
  15.   <body>
  16.     <div id='str1'>Body untuk JQUERY</div>
  17.     <div id='str2'>Body untuk NATIVE</div>
  18.    
  19. <script>
  20.  
  21. jq112(document).ready(function() {
  22.     jq112('<a>jQuery site</a>').attr('href', 'http://www.jquery.com/?p=112')
  23.     .appendTo('body');
  24.     jq112('<div>add text to jquery</div>').attr('info', 'only text')
  25.     .appendTo('#str1');
  26. });
  27.  
  28. //append direct
  29. document.getElementById('str2').innerHTML += '<div>add text to native</div>';
  30.  
  31. //append using element
  32. newElement = document.createElement('div');
  33. newElement.textContent = 'add text to native (2)';
  34. newElement.setAttribute('info', 'only text');
  35.  
  36. document.getElementById('str2').appendChild(newElement);
  37.  
  38.  
  39. </script>
  40.   </body>
  41. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement