0 votes
1 view
in Web Technology by (6.8k points)
I am new to web development and I do not know how to call a JavaScript function using an HTML button. Can someone tell me what are the different ways to do this?

1 Answer

0 votes
by (13k points)

There are multiple ways to call a JavaScript function using an HTML button for different situations and they are:

  1. Defining the function in HTML:

 <input id="click" type="button" value="click" onclick="Function();" />

  1. Adding it to a DOM property for an event:

document.getElementById(“click”).onclick =function;



//Something the function does


  1. You can also use an event handler :

var element=document.getElementById(“click”);



else if(element.attachEvent)


Welcome to Intellipaat Community. Get your technical queries answered by top developers !