How to call a function in jquery?

I have:


(function( $ ){

    $.fn.fade = function(options) {
        var settings = {
            'speed': 5000
        }
        if ( options ) {
            $.extend( settings, options );
        }

        var tickerIndex = 0;
        var tickerRef = this;
        function fadeOut() {
            var ticker = tickerRef.children().eq(tickerIndex);
            ticker.css("display", "block");
            //document.getElementById("ticker0").childNodes[tickerIndex].style.removeAttribute("filter");
            ticker.css('filter','none');
            //var node = document.getElementById(settings.id).childNodes[i];
            //node.style.removeAttribute("filter");

            ticker.fadeOut(settings.speed, function () {
                //$(this).css('filter','');

                //var node = document.getElementById(this).childNodes[i];
                //node.style.removeAttribute("filter");
                //document.getElementById("ticker0").style.removeAttribute("filter");
                ticker.css("display", "none");
                tickerIndex++;

                if (tickerIndex == tickerRef.children().length) {
                    tickerIndex = 0;
                }				
                fadeOut();
            });
        };		
		fadeOut();		
    };
	
})( jQuery );

I want to change fadeOut() to setTimeout(‘fadeOut()’, 10000) but it says fadeOut() is undefined. How should I call it?

Thanks!

jQuery has a method you can use called delay(), basically you use it like any other method but it does the same thing as calling a setTimeout() function manually.

http://api.jquery.com/delay/

Hi!

Is this how it is done?

fadeOut().delay(10000);

Thanks.

It doesn’t work. Please help. Thanks

The delay method needs to be declared before the fadeOut method, see the below example.

$('div').delay(10000).fadeOut();

Sorry Chris, I think you got me wrong.

I want the fadeOut() at lines 3 and 6 from the bottom of the code to call fadeOut() at a delay of 10000milisecs. Not a $(‘div’).

How should I call it? Thanks.


setTimeout(function() { fadeOut(); }, 10000);

or


setTimeout(fadeOut, 10000);

(both do the same thing, but I personally prefer the syntax of the former)

:slight_smile:

sorry…it says fadeOut() is undefined.