Professional Documents
Culture Documents
Sec-K22KN
Roll-No-67
Activity-04
Input:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM Manipulation Tasks</title>
<style>
body {
text-align: center;
margin-top: 50px;
}
#container {
margin-top: 20px;
}
</style>
</head>
<body>
<p id="paragraph">Original Text</p>
<button id="toggleButton">Toggle Image Visibility</button>
<img id="image" src="image.jpg" alt="Sample Image" style="display:
block;">
<button id="changeColorButton">Change Background Color</button>
<div id="container">
<p>This is the original content.</p>
</div>
<script>
const changeColorButton =
document.getElementById('changeColorButton');
changeColorButton.addEventListener('click', function() {
const randomColor = '#' +
Math.floor(Math.random()*16777215).toString(16);
document.body.style.backgroundColor = randomColor;
});
const newParagraph = document.createElement('p');
newParagraph.textContent = 'This is the dynamically created
paragraph.';
const container = document.getElementById('container');
container.appendChild(newParagraph);
</script>
</body>
</html>