0

I have a Function in java script it should print to a tag in HTML page. My code is:

function print(i) {
    document.getElementById('print').innerHTML = line[i].toString();
};

The problem is my print() function is being called many times, so i am getting the output of the final value after the execution.

1 Answer 1

2

That's because each time, you are resetting the value of innerHTML. Changing = to += will change it to what you want to achieve.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.