HTML DOM insertAdjacentText() मेथड निर्दिष्ट स्थिति पर टेक्स्ट स्ट्रिंग सम्मिलित करता है।
सिंटैक्स
निम्नलिखित सिंटैक्स है −
positionString और text पैरामीटर्स के साथ insertAdjacentText() कॉल करना
node.insertAdjacentText(“positionString”, text)
स्थिति स्ट्रिंग्स
यहां, “positionString” निम्नलिखित हो सकते हैं −
| positionString | विवरण |
|---|---|
| afterbegin | यह टेक्स्ट को नोड तत्व की शुरुआत के बाद सम्मिलित करता है |
| afterend | यह टेक्स्ट को नोड तत्व के बाद सम्मिलित करता है |
| beforebegin | यह टेक्स्ट को नोड तत्व से पहले सम्मिलित करता है |
| beforeend | यह टेक्स्ट को नोड तत्व के अंत से पहले सम्मिलित करता है |
उदाहरण
आइए InsertAdjacentText() मेथड का एक उदाहरण देखें −
<!DOCTYPE html> <html> <head> <title>insertAdjacentText()</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } </style> </head> <body> <form> <fieldset> <legend>insertAdjacentText( )</legend> <h1>भारत के पहले मुस्लिम राष्ट्रपति</h1> <h2 id="president">ए.पी.जे अब्दुल कलाम</h2> <input type="button" onclick="rectifyName()" value="नाम सुधारें"> </fieldset> </form> <script> function rectifyName() { var presidentH2 = document.getElementById("president"); presidentH2.insertAdjacentText("afterbegin", "डॉ. "); } </script> </body> </html>
आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा −
'नाम सुधारें' बटन पर क्लिक करने से पहले −

'नाम सुधारें' बटन पर क्लिक करने के बाद −
