-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9-40. Create HTML Elements 2.js
More file actions
32 lines (24 loc) · 1.01 KB
/
9-40. Create HTML Elements 2.js
File metadata and controls
32 lines (24 loc) · 1.01 KB
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
31
32
// Example code (Here i am not uploading HTML and CSS file to Github of this code)
/* Create HTML Element part 2 :
*/
var list = document.getElementById('todo-list');
var inputBox = document.getElementById('todo-input');
var btnAdd = document.getElementsByTagName('add-Item');
var currentInputValue = '';
inputBox, addEventListener('input', function (e) {
currentInputValue = e.target.value;
});
btnAdd.addEventListener('click', function () {
if (currentInputValue !== undefined && currentInputValue !== null && currentInputValue !== '') {
var newListElement = document.createElement('li')
var textNode = document.createTextNode(currentInputValue);
newListElement.appendChild(textNode);
newListElement.id = "item" + (List.childElementCount + 1);
list.appendChild(newListElement);
console.log(list.childElementCount);
inputBox.value = ''
currentInputValue = ''
}else {
alert('Please enter a valid item')
}
});