<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Dynamic Content Example</title>
    </head>
    <body>
    
        <!-- Button that triggers content addition -->
        <button id="myButton">Click Me</button>
        
        <!-- Container where "Hello, World!" will be added -->
        <div id="content"></div>
        
        <!-- Linking the external JavaScript file -->
        <script src="script.js"></script>
    </body>
</html>
// Get references to the button and content elements
const button = document.getElementById("myButton");
const content = document.getElementById("content");

// Define the function to handle button clicks
function handleClick() {
    // Create a new paragraph element
    const newText = document.createElement("p");
    newText.textContent = "Hello, World!";
    
    // Add the new paragraph to the content container
    content.appendChild(newText);
}

// Run handleClick when the button is clicked
button.addEventListener("click", handleClick);
Live Example: Dynamically Adding Content with JavaScript Click the button to try it out!
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Dynamic CSS Example</title>
    </head>
    <body>
    
        <!-- Button that triggers the background color change -->
        <button id="myBgButton">Change Background</button>
        
        <!-- Link to the external JavaScript file -->
        <script src="bg-script.js"></script>
    </body>
</html>
// Get the button element
const myBgButton = document.getElementById("myBgButton");

// Define the function that handles the button click
function myBghandleClick() {
  // Change the background color of the body to a random color
  const randomColor = generateRandomColor();
  document.body.style.backgroundColor = randomColor;
}

// Define a function to generate a random color
function generateRandomColor() {
  const letters = "0123456789ABCDEF";
  let color = "#";
  for (let i = 0; i < 6; i++) {
    color += letters[Math.floor(Math.random() * 16)];
  }
  return color;
}

// Run the handleClick function when the button is clicked
myBgButton.addEventListener("click", myBghandleClick);
Live Example: Dynamically Styling a Web Page with JavaScript Click the button to try it out!