Кроме того, в вашем методе traverse
вы должны получить элемент, используя document.getElementById('output')
вместо использования (неопределенной) переменной output
:
т.е:
function traverse(){
document.getElementById('output').innerHTML+='Test';
}
Вы также можете ускорить это, кэшируя узел (чтобы избежать вызова getElementById при каждом нажатии кнопки):
// Create a closure by wrapping the cached node in a self-executing
// function to avoid polluting the global namespace
var traverse = (function (nodeId) {
// Cache the node to be updated here
var node = document.getElementById(nodeId);
// This is the function that "traverse()" will call. Return this function,
// which will assign it to the variable traverse.
return function () {
node.innerHTML += 'test';
};
// Execute the function with the id of the node to cache, i.e. output
}('output'));