0

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.

Anthony
  • 804
  • 3
  • 12
  • 32

2 Answers2

0

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?

Community
  • 1
  • 1
Andreas Furster
  • 1,558
  • 1
  • 12
  • 28
-1
$('.myKnownClass').click(function() {

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

 });
Amit Soni
  • 1,437
  • 1
  • 9
  • 18
  • Why would you want this to happen every 200ms? I think you want `setTimeout`, but even that is a flawed solution as I mentioned above. – Rory McCrossan Apr 17 '14 at 13:00