var button1 document getElementsByClassNa me button button1 addEventLi

 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
33
34
var button1=document.getElementsByClassName('button')[0];
button1.addEventListener("click", add_elem1, false);
function add_elem1(event){
// alert('hello');
var left_container=document.getElementsByClassName('left_container')[0];
var right_container=document.getElementsByClassName('right_container')[0];
// left_container.parentNode.removeChild(left_container);
var elem=document.createElement('div');
var text=document.getElementsByClassName('inputType')[0].value;
var numberOfContainer=document.getElementsByClassName('inputType')[1].value;
elem.className="node";
elem.innerHTML=text;
var cross=document.createElement('div');
cross.className="cross";
elem.appendChild(cross);
cross.addEventListener("click", remove_elem, false);
if (numberOfContainer!=1 && numberOfContainer!=2){
alert('Номер колонки должен быть 1 или 2');
return;
}
if (numberOfContainer==1){
left_container.appendChild(elem);
}else{
right_container.appendChild(elem);
}
}
function remove_elem(event){
var elem=event.srcElement.parentElement;
return elem.parentNode ? elem.parentNode.removeChild(elem) : elem;
}