inline SVG scritping test

Here is a simple inline SVG example created by a script. The init() function called by the onload command works correctly, and the add1() function works if it is called at the same time. However, the add2() function called later with onclick does not work. Why?