+ 1
Javascript
I want to get alert when clicked on button , so anyone please help. https://code.sololearn.com/WSK8i3mRap4c/?ref=app
6 Réponses
+ 10
Remember to wrap JavaScript code in Sololearn's compiler in the window.onload
+ 5
GHOST ,,
As Ausgrindtube bro said,continue..
You can use script tag...
See this modified version of your code example..
https://code.sololearn.com/WxISCmJ8Hymb/?ref=app
+ 4
As Ausgrindtube mentioned. In the playground you have to wrap your function into the window.onload. This ensures the code is executed only after the entire page is loaded. Here's an example.
window.onload = function() {
const x = "HELLO";
document.getElementById("btn").onclick = function (){
alert(x); }
}
+ 2
Looks like it already works
+ 2
Thanks ausgrindtube
0
You didn’t specify the btn id