Victor Kimura
asked on
jquery plugin: call to method within plugin
Hi,
I have this plugin:
There is this method display() that is calling the other method display2() but display2 is never executed. How can I make it work?
I have the following in my as my init.js:
All the alerts are working except display2().
thanks,
Victor
I have this plugin:
(function( $ ){
var methods = {
init : function( options ) {
var settings = $.extend( {
'location' : 'top',
'background-color' : 'blue'
}, options);
alert ( settings.location );
},
show : function( ) {
// IS
},
hide : function( ) {
// GOOD
},
update : function( content ) {
// !!!
},
display : function ( test1, test2 ) {
var test1 = test1;
alert ( "test1: " + test1 + "\ntest2: " + test2 );
self.display2( test2 );
},
display2 : function ( test3 ) {
alert ( "test3: " + test3 );
}
};
$.fn.tooltip = function( method ) {
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
}
};
})( jQuery );
There is this method display() that is calling the other method display2() but display2 is never executed. How can I make it work?
I have the following in my as my init.js:
$(document).ready(function() {
// calls the init method
$('div').tooltip();
// calls the init method
$('div').tooltip({
'location' : 'left'
});
$().tooltip('display', 'John', '316');
});
All the alerts are working except display2().
thanks,
Victor
Can you try this. instead of self.
And define display2 before you call it
ASKER
this.display2 ( test2 );
The error is Uncaught TypeError: Object [object Object] has no method 'display2'
self.display2 ( test2 );
gives the same error.
tried this but it doesn't work:
$('').tooltip.display2( test2 );
No certain what you mean by "defining" display2 before it's called. How do I do that?
Thanks,
The error is Uncaught TypeError: Object [object Object] has no method 'display2'
self.display2 ( test2 );
gives the same error.
tried this but it doesn't work:
$('').tooltip.display2( test2 );
No certain what you mean by "defining" display2 before it's called. How do I do that?
Thanks,
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you. =)