HTML ऑब्जेक्ट एक HTML दस्तावेज़ के तत्व का प्रतिनिधित्व करता है।
आइए देखें कि HTML ऑब्जेक्ट को कैसे एक्सेस करें -
सिंटैक्स
निम्नलिखित वाक्य रचना है -
document.getElementsByTagName(“HTML”)
आइए HTML ऑब्जेक्ट का एक उदाहरण देखें -
उदाहरण
<!DOCTYPE html>
<html>
<head>
<style>
body{
text-align:center;
}
.btn{
background-color:lightblue;
border:none;
height:2rem;
border-radius:50px;
width:60%;
margin:1rem auto;
}
.show{
font-size:1rem;
font-weight:bold;
color:orange;
border:2px solid green;
padding:10px;
display:none;
}
</style>
</head>
<body>
<h1>DOM HTML Object Example</h1>
<button type="button" onclick="getContent()" class="btn">Click me to get content
inside HTML tag</button>
<div class="show"></div>
<script>
function getContent(){
var content=document.getElementsByTagName("HTML")[0].innerHTML;
document.querySelector(".show").innerHTML = content;
document.querySelector(".show").style.display ="block";
}
</script>
</body>
</html> आउटपुट
यह निम्नलिखित आउटपुट देगा -

इस पेज टैग के अंदर सभी सामग्री प्राप्त करने के लिए "नीला" बटन पर क्लिक करें -
