0

Cant interact with button (HTML & JS)

<button>Like</button> <script> $("button").on("click", function() { alert("Button Clicked!") }); </script> ---------- I am new to HTML / JS. Why can't I interact with this button with the code above?

12th Dec 2018, 7:41 PM
Brandon Kane
Brandon Kane - avatar
3 Réponses
+ 3
Yes, before using jQuery first I should import it. Then I am adding an "Id" to the button. Select the button with jQuery and then defined a function with event listener => "click".
12th Dec 2018, 8:21 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
You can see here my solution. I hope it helps you. https://code.sololearn.com/WUBggyqVOvXu/?ref=app
12th Dec 2018, 8:11 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Thanks very much. I noticed you added a JQuery script, named the button and assigned the JS code to the btn variable, which is the name of the button. I think I understand what you did. Thanks again for the response.
12th Dec 2018, 8:14 PM
Brandon Kane
Brandon Kane - avatar