impregnable fiend impregnable fiend - 1 year ago 63
Javascript Question

If first function is correct, got stuck in the simple situation

I know that my question is obviously ordinary, but I'm a bit newbie and dunno how shortly and, what most important, correctly perform that.
So, I've got something like this:

$('button').on('click', func1).on('click', func2);

As you can see I've got 2 'click' events on the same button, but
must execute only if
is correct. Dunno how properly write
statement here, any valuable help will be appreciated :)

Answer Source

If I understand you right, and on click event you want to execute func2 only if func1 returns non-falsey value, then why not to transform it to:

$('button').on('click', function() {
    func1() && func2();

    // same as:
    // if (func1())
    //     func2();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download