There is a simple code: http://jsbin.com/yulaturibe/edit?html,js,console,output
Js
// Функция отрисовки function Draw(val1, val2) { var Header = '<div id="left">'+val1+'</div><div id="right">'+val2+'</div>'; return Header; } var val1 = 1; var val2 = 5; document.getElementById('text').innerHTML=Draw(val1, val2); // Функция добавления left.onclick = function() { console.log(val1); val1++; return val1; }; HTML from 1 line:
<div id="text"></div> Question 2:
Why the updated val1 value is not displayed on the page, but increases in the console? And how to make it so that the page is increased?
How in this case to rewrite the script to get rid of global variables val1 and val2?
Drawonly once. The markup code is not connected in any way; the markup is always changed only manually. - Grundy