سؤال

Alright I have this :

$('.myKnownClass').click(function() {

            $('.menu').addClass('testingClass');

 });

When I click on the .myKnownClass, another script adds a div.menu, but it doesn't create it instantly (like 0.4 seconds, depends on the server).

Is there any way, within the "click", to wait till a div.menu is present on the body ?

Thanks.

هل كانت مفيدة؟

المحلول 2

$('.myKnownClass').click(function() {

            var interval = setInterval(function(){
                   if($(".menu").length){
                          $('.menu').addClass('testingClass');
                          clearInterval(interval);
                   }
            },200);

 });

نصائح أخرى

Maybe you could do something with jQuerys Deferreds. I don't really know how to use it, but maybe you can do something with it.

How can jQuery deferred be used?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top