Skip to content
Advertisement

Call onclick jQuery function once

How can I execute this function only one time? I tried bind or unbind but it doesn’t work

<uib-tab-heading onclick="myFunction()"><i class="fa fa-keyboard-o"></i> Typing Test </uib-tab-heading>
function myFunction() {
    alert("hit");   
}

Advertisement

Answer

Try this below :

Use this flag in your $document.ready scope (global scope)

var flag = false

if(!flag){

    function myFunction() {
        flag = true;
        alert("hit");   
    }

}
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement