Skip to content
Advertisement

Can I use function(e) twice or more in the same file?

Is it okay to use the same function in the same file twice or more

    document.getElementById('one').onlick = function test(e) 
    {
        var key = e.which;
        if(key === 13)
        {
            document.getElementById('two').click();
            return true;  
        }
    }

The other one is

    document.getElementById('elem').onlick = function test(e)
    { 
        document.getElementById('divtext').innerHTML=''; 
        e.preventDefault();   
        x--;
    }

Advertisement

Answer

function (e) is an anonymous function, you can have as many as you like.

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