HTML DOM insertAdjacentElement () विधि एक निर्दिष्ट स्थान पर एक तत्व सम्मिलित करती है।
सिंटैक्स
निम्नलिखित वाक्य रचना है -
पोजिशनिंग और एलिमेंट के मापदंडों के साथ इन्सर्टएडजेंट एलीमेंट () को कॉल करना
node.insertAdjacentElement(“positionString”, element)
स्थिति स्ट्रिंग्स
यहां, “positionString” निम्नलिखित हो सकते हैं -
| positionString वें> <वें शैली ="पाठ-संरेखण:केंद्र;">विवरण वें> | |
|---|---|
| शुरू के बाद | यह नोड तत्व की शुरुआत के बाद तत्व सम्मिलित करता है |
| बाद में | यह नोड तत्व के बाद तत्व सम्मिलित करता है |
| शुरुआत से पहले | यह नोड तत्व से पहले तत्व सम्मिलित करता है |
| पूर्वांत | यह नोड तत्व के अंत से पहले तत्व सम्मिलित करता है |
उदाहरण
आइए InsertAdjacentElement() . के लिए एक उदाहरण देखें विधि -
<!DOCTYPE html>
<html>
<head>
<title>insertAdjacentElement()</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>insertAdjacentElement( )</legend>
<h1>Family Tree</h1>
<span id="Father">Father --></span>
<span id="GrandFather">Grand Father --></span>
<span id="Myself">Myself</span>
<input type="button" onclick="rectifyTree()" value="Correct Family Tree">
</fieldset>
</form>
<script>
function rectifyTree() {
var FSpan = document.getElementById("Father");
var GFSpan = document.getElementById("GrandFather");
GFSpan.insertAdjacentElement("afterend", FSpan);
}
</script>
</body>
</html> आउटपुट
यह निम्नलिखित आउटपुट देगा -
‘परिवार के पेड़ को सही करें’ . पर क्लिक करने से पहले बटन -

‘परिवार के पेड़ को सही करें’ . पर क्लिक करने के बाद बटन -
