- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13_insertBefore.js
More file actions
Latest commit
24 lines (21 loc) · 764 Bytes
/
Copy path13_insertBefore.js
File metadata and controls
24 lines (21 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// createElement('element)
// createTextNode('text content')
// element.appendChild(childElement)
// insertBefore('element','location') -> not child
constcontainer=document.querySelector('.container');
constshp=document.querySelector('.shp');
// rhp
constrhp=document.createElement('h2');
consttitle=document.createTextNode('The Pirates of RHP');
rhp.appendChild(title);
rhp.classList.add('blue');
shp.classList.add('red');
// insertBefore
// rhp is element, and shp is location after rhp
container.insertBefore(rhp,shp);
// replace child
constheading6=document.createElement('h3');
consttextmarine=document.createTextNode('The marine ford');
heading6.appendChild(textmarine);
// replace child new, old
container.replaceChild(heading6,rhp);