Module 3 Assignment
Module 3 Assignment
<!DOCTYPE html>
<html>
<body>
<div id="myText">text1</div>
<script>
setTimeout(function(){
document.getElementById("myText").innerHTML="Hello,world!";
},2000);
</script>
</body>
</html>
Output:-
Question2:-
<!DOCTYPE html>
<html>
<body>
<div class="myDiv">text1</div>
<script>
setTimeout(function(){
document.querySelector(".myDiv").style.backgroundColor="blue";
},5000);
</script>
</body>
</html>
Output:-
Question3:-
<!DOCTYPE html>
<html>
<body>
<div id="container">
Old Paragraph
</div>
<script>
function addParagraph(){
</script>
</body>
</html>
Output; -
Question4:-
<!DOCTYPE html>
<html>
<head>
<title>
<style>
.hidden{
display:none;
}
</style>
</title>
</head>
<body>
<div id="content">
<p> Original content here.</p>
<button id="addElementButton">Add Element</button>
</div>
<script>
document.getElementById('addElementButton').addEventListener('click',function() {
var newElement = document.createElement('p');
newElement.textContent='this is a newly added element.';
newElement.id='newElement';
document.getElementById('content').appendChild(newElement);
setTimeout(function(){
var elementToRemove=document.getElementById('newElement');
if (elementToRemove){
elementToRemove.remove();
}
},5000);
});
</script>
</body>
</html>
Output:-
<!DOCTYPE html>
<html>
<head>
<title>button</button>
</title>
</head>
<body>
<button id="MyButton">click Me</button>
<p id="message"></p>
<script>
document.getElementById('MyButton').addEventListener('click',function() {
alert('Button clicked!');
document.getElementById('content').appendChild(newElement);
setTimeout(function(){
document.getElementById('message').textContent='Action performed after
timeout!';
},5000);
});
</script>
</body>
</html>
Output:-
After click: -
Question6:-
<!DOCTYPE html>
<html>
<head>
<title></button>
< </title>
</head>
<body>
<div class="hoverDiv">Hover over me</div>
<script>
document.querySelector('.hoverDiv').addEventListener('mouseover',function(){
this.style.backgroundColor='yellow';
});
</script>
</body>
</html>
Output;-
Output After change its background color: -