Advertisement
lemansky

Untitled

Feb 28th, 2024
1,282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.13 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Dynamic JavaScript Highlighter</title>
  7.     <style>
  8.         .highlighted {
  9.             background-color: gold;
  10.             padding:4px;
  11.             margin: 8px;
  12.         }
  13.         textarea{
  14.             width:100%;
  15.         }
  16.     </style>
  17. </head>
  18. <body>
  19.  
  20. <textarea id="jsCode" rows="10" cols="50"></textarea>
  21.  
  22. <button id="code">Apply Code</button>
  23.  
  24. <div class="highlighted">Element 1</div>
  25. <div class="highlighted">Element 2</div>
  26. <div class="highlighted">Element 3</div>
  27. <div class="highlighted">Element 4</div>
  28. <div class="highlighted">Element 5</div>
  29. <div class="highlighted">Element 6</div>
  30. <div class="highlighted">Element 7</div>
  31.  
  32. <script>
  33.     document.querySelector('#code').addEventListener('click', (e) => {
  34.         const jsCode = document.querySelector('#jsCode').value;
  35.  
  36.         try {
  37.             eval(jsCode);
  38.         } catch (error) {
  39.             console.error('Error in the provided JavaScript code:', error);
  40.         }
  41.     });
  42. </script>
  43.  
  44. </body>
  45. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement