-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
30 lines (21 loc) · 1.27 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// const ulWithExistingHtml = document.querySelector(".ul-existing-html");
const ul = document.querySelector(".ul-insert-html-example");
const ulAfterbegin = document.querySelector(".ul-afterbegin");
const ulBeforeend = document.querySelector(".ul-beforeend");
const ulBeforebegin = document.querySelector(".ul-beforebegin");
const ulAfterend = document.querySelector(".ul-afterend");
const li = `<li><li> element added by <span class = violet-color-text>JavaScript</span></li>`;
ul.insertAdjacentHTML("afterbegin", li);
ulAfterbegin.insertAdjacentHTML("afterbegin", li);
ulBeforeend.insertAdjacentHTML("beforeend", li);
ulBeforebegin.insertAdjacentHTML("beforebegin", li);
ulAfterend.insertAdjacentHTML("afterend", li);
/* adding <li> element by by click on button element */
const buttonHtmlElement = `<button class="button-add-html-element">Add <li> element</button>`;
const ulParentEl = document.querySelector("ul.parent-element-for-button");
const liAddedByClick = `<li><li> added by "click" (<span class="red-color-text">JavaScript</span>)</li>`;
ulParentEl.insertAdjacentHTML("beforebegin", buttonHtmlElement);
const button = document.querySelector("button");
button.addEventListener("click", () => {
ulParentEl.insertAdjacentHTML("afterbegin", liAddedByClick);
});