Function is not defined, failed to load sources jQuery

I have this jquery code:

$(document).ready(function() {
            function slideSwitch() {
                var $active = $('#slideShow');

                if ( $active.length == 0 ) $active = $('#slideShow IMG:last');

                var $next =  $ ? $
                    : $('#slideShow IMG:first');


                $next.css({opacity: 0.0})
                    .animate({opacity: 1.0}, 1000, function() {
                        $active.removeClass('active last-active');

                setInterval( "slideSwitch()", 5000 );


And it errors with slideSwitch() is not defined?? any ideas?


If you use a string with setInterval it will be evaludated in the scope of the window object, and as you declared the function locally in another function, it's not available globally.

Just use the function name instead of a string with code that calls the function:

window.setInterval(slideSwitch, 5000);

This will pass a reference to the function instead of a string, so it doesn't rely on the name of the function when it's called.

Need Your Help

How does Entity Framework insert new values?

c# linq entity-framework

I have another question kind of relative to this but I'd like to separate them for clarity reasons.

Best way of binding onchange event on every form field using Rails 3, UJS/jQuery

jquery ajax ruby-on-rails-3 javascript-events onchange

I want to make form submission on every onchange() form field event to get "live search results count" in separate css box. (Like here when you change some form field value you get immediate "searh

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.