Thats because WordPress TinyMCE editor strips out the onclick attribute as it sees it as a possible risk. There are several solutions if you google “stop WordPress from stripping HTML”. If you’re using the Gutenberg block editor, the HTML Block is more forgiving and will ( probably ) allow it.
But… adding an onclick event in HTML is bad practice and should be avoided.
You’re better off adding an event listener in you JS eg.