Search
 
SCRIPT & CODE EXAMPLE
 

HTML

onclick alert javascript

<!-- 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>
Comment

javascript onclick alert

<button onclick="alertFunction()"> Click</button>

  <script>
        function alertFunction() {
            alert("Hello World");
        }
    </script>
Comment

alert onclick javascript

// html part 

<button id="btn" onclick="alet()"></button>

// js part 

let btn = document.getElemntById("btn")

function alet() {
alert("Hello the world")

}
Comment

PREVIOUS NEXT
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 
::  
ADD CONTENT
Topic
Content
Source link
Name
3+1 =