java
1 month ago in JavaScript
var the_heading = document.getElementById("heading"),
the_ul = document.getElementById("list"),
the_button = document.getElementById("button"),
the_li = document.getElementById("list").getElementsByTagName("li"),
counter = 1;

/*the_li[0].addEventListener("click" , function(){
the_heading.innerHTML = the_li[0].innerHTML;
});*/
for (let i = 0; i < the_li.length; i++) {
the_li[i].addEventListener("click" , ahmad)
function ahmad ()
{ the_heading.innerHTML = the_li[i].innerHTML;
};
};
the_button.onclick = function ()
{ the_ul.innerHTML = the_ul.innerHTML + "<li>New Item "+ counter +"</li>";
counter ++;
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19