-The document object model is a way for JavaScript to access and control the html elements in a webpage.
- It can change the content style of the webpage while running program.
Example: Show /Hide Password
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Show/hide password</h1>
<input type="text" id="password" placeholder="type....">
<button id="btn" >show</button>
<script>
const password=document.getElementById("password");
const buttons=document.getElementById("btn")
buttons.addEventListener("click",function(){
if(password.type==="password"){
password.type="text"
buttons.innerText="hide"
}
else{
password.type="password"
buttons.innerText="show"
}
})
</script>
</body>
</html>
Top comments (0)