Call function from another JavaScript function?

0 like 0 dislike
5 views
Good afternoon.
There are two simple functions.
<!DOCTYPE html>TestPoint No. 1: var a = 2;function Test(){switch(a){case 1:document.write(1);break;case 2:document.write(2);break;}};function Test1(){Test();document.getElementById('user_1').innerHTML = a;}setInterval(Test1, 1000);

When you call the function Test1 must run first the Test function, and then code Test1.
However, I get "Uncaught TypeError: Cannot set property 'innerHTML' of null at Test1".
What is my mistake?
by | 5 views

1 Answer

0 like 0 dislike
document.write(1); Test function erases the document and so removes the element of user_1. In function Test1 you are trying to refer to it, and it was gone, so the error and write "can Not set the innerHTML property to null"
by

Related questions

0 like 0 dislike
3 answers
0 like 0 dislike
4 answers
0 like 0 dislike
1 answer
0 like 0 dislike
4 answers
0 like 0 dislike
1 answer
asked Jun 9, 2019 by kibernetshow
110,608 questions
257,186 answers
0 comments
33,770 users