1

I want to perform some task in jQuery when some other function in my JavaScript is called.

To explain the question: Let's say I have function foo(){..} in JavaScript.

While my code is under execution phase, I want to perform some action using jQuery whenever function foo(){..} is called.

Rough Demo:

    <!DOCTYPE html>
    <title>Demo</title>
    <body>
    <script>
    function foo()
    {
        alert("Function Called");
    }

    ...Some code....
if(some condition)    
    foo();   //function Call   - I want to execute jQuery event when this line is executed.
else
    woo();
    </script>
    </body>
    </html>

Is there any event handler which can achieve this?

  • What action do you want to perform? – BravoZulu Aug 06 '15 at 14:09
  • I want to perform an ajax call when this function is executed. Actually there are multiple ajax calls when respective functions are called. –  Aug 06 '15 at 14:22
  • You could add the AJAX call inside your `foo()` function.. – BravoZulu Aug 06 '15 at 14:36
  • @BravoZulu: That is correct. But, then things get very nested. I am trying to make distinct snippets. And any event handler which could perform action on execute of some function, will fulfill my purpose. –  Aug 06 '15 at 14:43

1 Answers1

0

After seeing the updated question, the only way to handle this would be to put your jquery function at the same level as function foo() and call it from there as explained in this example.

Community
  • 1
  • 1
Trasiva
  • 494
  • 14
  • 29