var button document getElementsByClassNa me button var sum button addE

 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
var button=document.getElementsByClassName('button')[0];
var sum = 0;
button.addEventListener("click", run, false);
function run(){
// var container_left=document.getElementsByClassName('container_left')[0];
var container_right=document.getElementsByClassName('container_right')[0];
var stringInContainer=document.createElement('div');
var name=document.getElementsByClassName('string')[0].value;
var price=document.getElementsByClassName('string')[1].value;
var real_price = parseInt(price);
stringInContainer.className="str";
stringInContainer.innerHTML=name+' '+price;
var cross=document.createElement('div');
cross.className="cross";
stringInContainer.appendChild(cross);
cross.addEventListener("click", remove_stringInContainer, false);
if (price>=1){
sum += real_price;
container_right.appendChild(stringInContainer);
}
document.getElementsByClassName('total')[0].value = sum;
//alert(sum);
}
function remove_stringInContainer(event){
var stringInContainer=event.srcElement.parentElement;
return stringInContainer.parentNode ? stringInContainer.parentNode.removeChild(stringInContainer) : stringInContainer;
}