How you add a onclick function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How you add a onclick function

How do you add a onclick function so when you click it it alerts On HTML...

17th Sep 2018, 9:42 PM
Little Cupcake
Little Cupcake - avatar
1 Answer
+ 1
Use the attribute onclick to call the JS function after the onclick event is executed: onclick="myFunction();" The onclick attribute can be applied to many HTML tags👍 F.E.: In JS u create a function myFunction() that executes the code related to the function. function myFunction() { alert ("You clicked me!"); } Hope it helps👍
17th Sep 2018, 11:23 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar