HTML DOM सम्मिलित करेंआसन्नHTML () विधि
उदाहरण
शीर्ष लेख तत्व के बाद एक नया <p> तत्व डालें:
var h = document.getElementById("myH2");
h.insertAdjacentHTML("afterend",
"<p>My new paragraph</p>");
परिभाषा और उपयोग
insertAdjacentHTML()
विधि एक निर्दिष्ट स्थिति में HTML के रूप में एक पाठ सम्मिलित करती है ।
कानूनी स्थिति मान हैं:
"बाद में" "बाद में"
"पहले से शुरू
"
"पहले से"
ब्राउज़र समर्थन
तालिका में संख्याएं पहले ब्राउज़र संस्करण को निर्दिष्ट करती हैं जो पूरी तरह से विधि का समर्थन करता है।
Method | |||||
---|---|---|---|---|---|
insertAdjacentHTML() | 1 | 4 | 8 | 4 | 7 |
वाक्य - विन्यास
node.insertAdjacentHTML(position, text)
पैरामीटर मान
Parameter | Type | Description |
---|---|---|
position | String | Required. A position relative to the element. Legal values: "afterbegin" - After the beginning of the element (as the first child) "afterend" - After the element "beforebegin" - Before the element "beforeend" - Before the end of the element (as the last child) |
text | String | The text you want to insert |
और ज्यादा उदाहरण
उदाहरण
"आफ्टरबीन" मान का उपयोग करना:
h.insertAdjacentHTML("afterbegin", "<span style='color:red'>My span</span>");
उदाहरण
"पहले से शुरू" मान का उपयोग करना:
h.insertAdjacentHTML("beforebegin", "<span style='color:red'>My span</span>");
उदाहरण
"पहले से" मान का उपयोग करना:
h.insertAdjacentHTML("beforeend", "<span style='color:red'>My span</span>");