<!-- 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 :: tag input type float number html |
Html :: |
:: |
Html :: |
:: bootstrap outline buttons |
:: |
:: dropdown in html |
:: |
:: |
:: |
Html :: |
:: |
:: |
:: open link in a new tab hmtl |
:: html add image from remote source |
:: |
:: html void |
Html :: |
:: |
:: |
:: |
Html :: |
:: |
Html :: |
:: |
:: |
:: happy birthday html animation |
:: |