If one.button
is null
, then that's just because document.getElementById("one");
did not find a DOM object when you ran the constructor for your number()
object and thus is returned null
.
That could either be because there is no object in the page with that id or it could be becase you are running this code before the page has finished loading and thus that object does not yet exist when you run the code.
You would have to show more of the overall page context (where the code is executing in relation to the parsing of the page DOM) for us to know exactly which situation was happening here.
A common fix for the situation where you're running the code too soon is to move the <script>
tag where this code resides to right before the </body>
tag. This will ensure that all DOM elements exist when this code runs. For a more complete explanation of this issue see this answer: pure JavaScript equivalent to jQuery's $.ready() how to call a function when the page/dom is ready for it.