Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey guys, I am just wondering if it is possible to call a javascript function inside a JQuery plugin? I want to call a function inside my jquery file if a certain condition is met.

JavaScript
var displayMessage = function (objNotification) {

              this.hello = function () {
                   alert('Condition met!');
               }

               var json = JSON.parse(objNotification);
//this is where I call my plugin where I pass a JSON object. I want to call the function hello in here?
               notification(json);
           };




Thanks in advance guys.
Posted
Comments
Sergey Alexandrovich Kryukov 21-May-13 12:34pm    
This is what always done in jQuery, otherwise how it would even work? :-)
—SA

1 solution

Yes, this is possible and not even a problem. The function to be called should be created as a function object before (in time order, not in the order of the code text) calling, that's all. This is scripting, very relaxed in this respect.

Just call it; what are you waiting for, my approval? :-)

—SA
 
Share this answer
 
Comments
frostcox 21-May-13 12:38pm    
Hey excuse my ingrorance but I tried calling the this.hello() inside my plugin but I still get an error. Thanks for your help
What is the error ?
Do you see any error in console tab of FireBug in FireFox ?
Sergey Alexandrovich Kryukov 21-May-13 14:10pm    
In the code you've shown, you never call this function. We cannot help you with your code if you not showing the exact code which cases the problem.
—SA
frostcox 21-May-13 13:51pm    
He yes just says hello is underfined or not an object
Sergey Alexandrovich Kryukov 21-May-13 14:08pm    
Define it. Make an object (assign). Run under the debugger to see in what line, run again and examine the offending object. Take care about it.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900