<element onclick="fun()">
object.onclick=function() { myScript };
object.addEventListener("click", myScript);
<!DOCTYPE html>
<html>
<head>
<script>
function fun() {
alert("Welcome to the bianchenghao6.com");
}
</script>
</head>
<body>
<h3> This is an example of using onclick attribute in HTML. </h3>
<p> Click the following button to see the effect. </p>
<button onclick="fun()"> Click me</button>
</body>
</html>
Click the following button to see the effect.
<!DOCTYPE html>
<html>
<head>
<title> onclick event </title>
</head>
<body>
<h3> This is an example of using onclick event. </h3>
<p> Click the following text to see the effect. </p>
<p id="para"> Click me</p>
<script>
document.getElementById("para").onclick=function() {
fun()
} ;
function fun() {
document.getElementById("para").innerHTML="Welcome to the bianchenghao6.com";
document.getElementById("para").style.color="blue";
document.getElementById("para").style.backgroundColor="yellow";
document.getElementById("para").style.fontSize="25px";
document.getElementById("para").style.border="4px solid red";
}
</script>
</body>
</html>
Click the following text to see the effect.
Click me
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h3> This is an example of using click event. </h3>
<p> Click the following text to see the effect. </p>
<p id="para"> Click me</p>
<script>
document.getElementById("para").onclick=function() {
fun()
} ;
function fun() {
document.getElementById("para").innerHTML="Welcome to the bianchenghao6.com";
document.getElementsByTagName("body")[0].style.color="blue";
document.getElementsByTagName("body")[0].style.backgroundColor="lightgreen";
document.getElementsByTagName("body")[0].style.fontSize="25px";
document.getElementById("para").style.border="4px solid red";
}
</script>
</body>
</html>
Click the following text to see the effect.
Click me