Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Dynamic JavaScript Highlighter</title>
- <style>
- .highlighted {
- background-color: gold;
- padding:4px;
- margin: 8px;
- }
- textarea{
- width:100%;
- }
- </style>
- </head>
- <body>
- <textarea id="jsCode" rows="10" cols="50"></textarea>
- <button id="code">Apply Code</button>
- <div class="highlighted">Element 1</div>
- <div class="highlighted">Element 2</div>
- <div class="highlighted">Element 3</div>
- <div class="highlighted">Element 4</div>
- <div class="highlighted">Element 5</div>
- <div class="highlighted">Element 6</div>
- <div class="highlighted">Element 7</div>
- <script>
- document.querySelector('#code').addEventListener('click', (e) => {
- const jsCode = document.querySelector('#jsCode').value;
- try {
- eval(jsCode);
- } catch (error) {
- console.error('Error in the provided JavaScript code:', error);
- }
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement