javascript calling two events on one click code example

Example 1: how to make a button jump between two functions when clicked in javascript

function buttonClick() {
    //do stuff
    this.onclick = notButtonClick; //function reference to nBC
}

function notButtonClick() {
    //do more stuff
    this.onclick = buttonClick; //function reference to original function
}

var el = document.getElementById("numberonebutton"); //let for ES6 aficionados 
el.onclick = buttonClick; //again, function reference, no ()

Example 2: call two methods on button click

<input id="btn" type="button" value="click" onclick="pay(); cls();"/>

Tags:

Html Example