8000 example · last-endcode/JavaScript-DOM@2b655b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2b655b5

Browse files
committed
example
1 parent b88af94 commit 2b655b5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

23_example.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const container = document.querySelector('.container');
2+
const btn = document.querySelector('.btn');
3+
4+
function addElement(e) {
5+
// create element h1
6+
const heading_1 = document.createElement('h1');
7+
// add class with the name heading
8+
heading_1.classList.add('heading');
9+
// create Text content
10+
heading_1.textContent = 'The pirates of SHP';
11+
// show to browser pages
12+
container.appendChild(heading_1);
13+
}
14+
15+
// here if heading release and click get text hello there
16+
container.addEventListener('click', function (e) {
17+
if (e.target.classList.contains('heading')) {
18+
console.log('hello there ');
19+
}
20+
});
21+
btn.addEventListener('click', addElement);

0 commit comments

Comments
 (0)
0