From fcd82532291093fa81e9c92e60e7006b0db321fb Mon Sep 17 00:00:00 2001 From: Hamza Khan Lodhi <134397582+hamzalodhi2023@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:33:11 +0500 Subject: [PATCH] JS-insert.html --- JS-insert.html | 617 +++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 3 + 2 files changed, 620 insertions(+) create mode 100644 JS-insert.html diff --git a/JS-insert.html b/JS-insert.html new file mode 100644 index 0000000..6d42f65 --- /dev/null +++ b/JS-insert.html @@ -0,0 +1,617 @@ + + +
+ + +
+ The insertAdjacentElement()
method inserts a an
+ element into a specified position.
+
+ Value + |
+
+ Description + |
+
---|---|
+ afterbegin + |
+
+ After the beginning of the element (first child) + |
+
+ afterend + |
+
+ After the element + |
+
+ beforebegin + |
+
+ Before the element + |
+
+ beforeend + |
+
+ Before the end of the element (last child) + |
+
element.insertAdjacentElement(position, element)
+ or
+node.insertAdjacentElement(position, element)
+
+
+ Parameter | +Description | +
position | +
+ Required. + A position relative to the element: + afterbegin + afterend + beforebegin + beforeend + |
+
element | +The element to insert. | +
+ The insertAdjacentHTML()
method inserts HTML code
+ into a specified position.
+
Value | +Description | +
---|---|
afterbegin | +After the beginning of the element (first child) | +
afterend | +After the element | +
beforebegin | +Before the element | +
beforeend | +Before the end of the element (last child) | +
element.insertAdjacentHTML(position, html)
+ or
+node.insertAdjacentHTML(position, html)
+
+ Parameter | +Description | +
position | +
+ Required. + A position relative to the element: + afterbegin + afterend + beforebegin + beforeend + |
+
html | +The HTML to insert. | +
<!DOCTYPE html>
+<html>
+<head>
+ <title>DOM Navigation</title>
+ <style>
+ #test{
+ background: #ffff00;
+ width: 800px;
+ height: 200px;
+ padding: 10px 10px;
+ margin: 0 auto;
+ }
+ </style>
+</head>
+<body>
+ <div id="test">
+ <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur aperiam eos vel consequatur. Delectus voluptas
+ dolorem id exercitationem, ad ipsam consectetur hic ullam provident! Adipisci exercitationem ipsam rerum sunt
+ doloremque magni soluta, delectus maiores, sapiente quasi labore praesentium accusamus earum cum nam saepe qui?
+ Accusamus provident quo perferendis sint sed.</p>
+ </div>
+ <script src="js/dom-create.js"></script>
+</body>
+</html>
+
+ // insertAdjacentElement Method
+
+var newElement = document.createElement("h2");
+
+var newText = document.createTextNode("This is just element");
+
+newElement.appendChild(newText);
+
+var target = document.getElementById("test");
+
+target.insertAdjacentElement("afterbegin",newElement);
+
+
+// insertAdjacentHTML Method
+
+var newElement = "<h2>This is just Html</h2>";
+
+var target = document.getElementById("test");
+
+target.insertAdjacentHTML("afterend",newElement);
+
+// insertAdjacentText Method
+
+var newText = "<h2>This is just Text</h2>";
+
+var target = document.getElementById("test");
+
+target.insertAdjacentHTML("beforeend",newText);
+
+
+