HTML DOM innerText प्रॉपर्टी वापस आती है और हमें HTML तत्व की आंतरिक टेक्स्ट सामग्री को संशोधित करने की अनुमति देती है।
सिंटैक्स
निम्नलिखित वाक्य रचना है -
1. आंतरिक पाठ लौटाना
object.innerText
2. आंतरिक पाठ सेट करना
object.innerText=”text”
उदाहरण
आइए इनरटेक्स्ट प्रॉपर्टी का एक उदाहरण देखें -
<!DOCTYPE html>
<html>
<head>
<style>
body{
text-align:center;
}
.box{
background-color:#347924;
width:100px;
padding:10px;
text-align:center;
font-weight:bold;
font-size:1.5rem;
color:white;
margin:1rem auto;
}
</style>
</head>
<body>
<h1>innerText property Example</h1>
<div class="box">
</div>
<button onclick="writeHi()">Write Hi</button>
<button onclick="writeHello()">Write Hello</button>
<script>
function writeHi() {
var outerBox = document.querySelector('.box');
outerBox.innerText ='HI';
}
function writeHello() {
var outerBox = document.querySelector('.box');
outerBox.innerText ='HELLO';
}
</script>
</body>
</html> आउटपुट
यह निम्नलिखित आउटपुट देगा -

“नमस्ते लिखें/नमस्ते लिखें . पर क्लिक करें हरे बॉक्स के आंतरिक पाठ को बदलने के लिए बटन।
