JavaScript

Call two functions from the same onClick event in JavaScript

If you want to call or execute multiple functions in one click, use a semicolon ‘;’ between the functions as shown below:

onclick = "function1(); function2()"

 

How to Call two functions from the same onClick event in JavaScript
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Call two functions from the same onClick event</title>
	</head> 
	<body>
		<script>
		function function1(){
			alert("function1 () is executed");
		}
		 
		function function2(){
			alert("function2() is executed");
		}
		</script>
		
		<button type="button" onclick="function1();function2();">Click here</button>
	</body>
</html>
Result
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *