- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23_example.js
More file actions
Latest commit
21 lines (19 loc) · 660 Bytes
/
Copy path23_example.js
File metadata and controls
21 lines (19 loc) · 660 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
constcontainer=document.querySelector('.container');
constbtn=document.querySelector('.btn');
functionaddElement(e){
// create element h1
constheading_1=document.createElement('h1');
// add class with the name heading
heading_1.classList.add('heading');
// create Text content
heading_1.textContent='The pirates of SHP';
// show to browser pages
container.appendChild(heading_1);
}
// here if heading release and click get text hello there
container.addEventListener('click',function(e){
if(e.target.classList.contains('heading')){
console.log('hello there ');
}
});
btn.addEventListener('click',addElement);