Skip to content

Commit c3a0b8b

Browse files
JS-DOM(create element)
1 parent b541df9 commit c3a0b8b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

JavaScript-DOM/app.js

+21
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,24 @@ const listLight = document.querySelectorAll('li:nth-child(odd'); //get all query
8282
listLight.forEach(function (li, index) {
8383
li.style.background = '#ccc';
8484
})
85+
86+
// ## create new element ##
87+
const li = document.createElement('li');
88+
89+
// ### add class ###
90+
li.className = 'list-group-item d-flex flex-row-reverse justify-content-between';
91+
92+
// ### add id ###
93+
li.id = 'new-item'
94+
95+
// ### add attribute ###
96+
li.setAttribute('title', 'new item')
97+
98+
// ### add innerHTML ###
99+
li.innerHTML = '<a href="/" class="btn btn-danger btn-sm delete-item">x</a>';
100+
101+
// Create append text node
102+
li.appendChild(document.createTextNode("This New Text"))
103+
104+
// execution new element
105+
document.querySelector('ul.list-group').appendChild(li);

0 commit comments

Comments
 (0)