How to trigger js function from click event

Correct me if I am wrong, but your example was done in python, correct? Is there a way to do that same functionality only in javascript?