Both do the same. (2) is more modern syntax as onclick DOM attributes are deprecated.
https://stackoverflow.com/ might be better suited for specific programming language questions.
https://stackoverflow.com/ might be better suited for specific programming language questions.