<!-- Best practice -->
<button id="btn1">Click me!</button>
<script>
document.getElementById("btn1").addEventListener("click", function() {
window.alert("You clicked me!");
});
</script>
<!-- Still valid -->
<button id="btn2">Click me!</button>
<script>
document.getElementById("btn2").onclick = function() {
window.alert("You clicked me!");
};
</script>
<!-- A different version of the above -->
<button id="btn3" onclick="btn3ClickHandler()">Click me!</button>
<script>
function btn3ClickHandler() {
window.alert("You clicked me!");
}
</script>
<button onclick="alertFunction()"> Click</button>
<script>
function alertFunction() {
alert("Hello World");
}
</script>
// html part
<button id="btn" onclick="alet()"></button>
// js part
let btn = document.getElemntById("btn")
function alet() {
alert("Hello the world")
}
Code Example |
---|
Html :: mobile prevent zoom |
Html :: how to convert a html canvas into a png file |
Html :: href disable underline |
Html :: open email client from html |
Html :: json placeholder limit |
Html :: html estrutura |
Html :: how to use google drive image in html |
Html :: change tab icon html |
Html :: Change the required text |
Html :: html image fallback |
Html :: video url html |
Html :: meta description |
Html :: align image center of webpage |
Html :: audio tag disable download |
Html :: add favicon to website html |
Html :: video tag html |
Html :: external js |
Html :: calendar input |
Html :: html viewport meta tag |
Html :: dropdown bootstrap 5 |
Html :: how to remove right clickk option from video tag in html |
Html :: vscode-jest intellisense not working |
Html :: how to make a yourbue icon in html |
Html :: how to add links |
Html :: angular.io hide |
Html :: 9+15 |
Html :: metasploit default login |
Html :: html video controls |
Html :: add link behind a button in html |
Html :: vuetify tooltip |