I\'ve seen that you can attach events like this
can you do the same
Yes, you can (and should!).
document.getElementById('myButton').onclick = myFunction;