0

I am new to webdesign. Been doing it for half a year now. I am trying to work with JS and I can't figure this out... I got this code:

$(window).load(function(){ 
    $('div#contact1').click(function(e){    
        $('div#contact1').fadeOut('slow', function(){
            $('div#contact2').fadeIn('slow');
        });
    }); 
    $('div.close3').click(function(e){    
        $('div#contact2').fadeOut('slow', function(){
            $('div#contact1').fadeIn('slow');
        });
    });
});

I want to fadeout the div contact2 with the div#close3 and with the escape key.

Oussama el Bachiri
  • 18,687
  • 3
  • 15
  • 22

1 Answers1

1

add this:

$(document).keyup(function(e){
    if (e.keyCode == 27) { 
        $('div#contact2').fadeOut('slow', function(){
            $('div#contact1').fadeIn('slow');
        });
    }
});

Source: Which keycode for escape key with jQuery

Community
  • 1
  • 1
Bill
  • 3,478
  • 23
  • 42
  • Somehow if I add anything to the js concerning the fadeout. The whole fade in fade out wont work at all... – Oussama el Bachiri Mar 27 '13 at 12:45
  • I don't understand, maybe you can debug to find out why and I'll try to fix it. If you copy/pasted my code, try again as I've updated it. – Bill Mar 27 '13 at 12:49
  • If you don't have any more questions, could you mark my answer as correct? Thanks :) – Bill Mar 27 '13 at 13:02