Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lab
- 5a) Append row to table
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Append Row to Table</title>
- </head>
- <body>
- <h1>Append Row to Table</h1>
- <!-- Table with an initial row -->
- <table id="myTable">
- <tr>
- <td>Row 1, Cell 1</td>
- <td>Row 1, Cell 2</td>
- </tr>
- </table>
- <!-- Button to append a row -->
- <button onclick="appendRow()">Add Row</button>
- <script>
- function appendRow() {
- // Get a reference to the table
- var table = document.getElementById("myTable");
- // Create a new row and cells
- var newRow = table.insertRow();
- // Create two cells for the new row
- var cell1 = newRow.insertCell(0);
- var cell2 = newRow.insertCell(1);
- // Add content to the cells (you can customize this)
- cell1.innerHTML = "New Row, Cell 1";
- cell2.innerHTML = "New Row, Cell 2";
- }
- </script>
- </body>
- </html>
- 5b) append anchor tag and link
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Append Anchor Tag</title>
- </head>
- <body>
- <h1>Append Anchor Tag</h1>
- <!-- Button to append the anchor tag -->
- <button onclick="appendAnchor()">Add Anchor Tag</button>
- <!-- Container for the anchor tag -->
- <div id="anchorContainer"></div>
- <script>
- function appendAnchor() {
- // Get a reference to the container
- var container = document.getElementById("anchorContainer");
- // Create an anchor tag
- var anchorTag = document.createElement("a");
- // Set the href attribute to the URL of the page you want to redirect to
- anchorTag.href = "https://example.com"; // Replace with your desired URL
- // Set the anchor text
- anchorTag.textContent = "Click me to go to the new page";
- // Append the anchor tag to the container
- container.appendChild(anchorTag);
- }
- </script>
- </body>
- </html>
- 5c1) color changing with mouse over
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Button Color Change</title>
- </head>
- <body>
- <h1>Change Button Color on Hover</h1>
- <!-- Button to change color on mouseover -->
- <button id="myButton" onmouseover="changeColor()">Hover over me</button>
- <script>
- function changeColor() {
- // Get a reference to the button element
- var button = document.getElementById("myButton");
- // Change the button's background color on mouseover
- button.style.backgroundColor = "blue"; // Change to your desired color
- }
- </script>
- </body>
- </html>
- 5c2) change color button on hover
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Button Color Change on Hover</title>
- </head>
- <body>
- <h1>Change Button Color on Hover</h1>
- <!-- Button to change color on mouseover and revert on mouseout -->
- <button id="myButton" onmouseover="changeColor(this, 'blue')" onmouseout="changeColor(this, 'red')">Hover over me</button>
- <script>
- function changeColor(element, newColor) {
- // Change the button's background color
- element.style.backgroundColor = newColor;
- }
- </script>
- </body>
- </html>
- 5c3) change color button on click
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Button Color Change on Click</title>
- </head>
- <body>
- <h1>Change Button Color on Click</h1>
- <!-- Button to change color on click -->
- <button id="myButton" onclick="changeColor()">Click me</button>
- <script>
- function changeColor() {
- // Get a reference to the button element
- var button = document.getElementById("myButton");
- // Change the button's background color
- button.style.backgroundColor = "blue"; // Change to your desired color
- }
- </script>
- </body>
- </html>
- 5d) change colour background with dropdown
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Button Color Change on Click</title>
- </head>
- <body>
- <h1>Change Button Color on Click</h1>
- <!-- Button to change color on click -->
- <button id="myButton" onclick="changeColor()">Click me</button>
- <script>
- function changeColor() {
- // Get a reference to the button element
- var button = document.getElementById("myButton");
- // Change the button's background color
- button.style.backgroundColor = "blue"; // Change to your desired color
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement