I have 3 div
parts in my HTML
document, and i am trying to toggle between each other whenever the key press. The idea is, when a key press event is occured, i got the id
of the current div
and depending on that id
, i fade in the right div
(if it's div 1, fade in div 2, etc.).
My HTML code is the following:
<div id="home" class="current">
<p align="center">Home</p>
<p align="center">
Some content
</p>
</div>
<div id="about">
<p align="center">About</p>
<p align="center">
Some content
</p>
</div>
<div id="contact">
<p align="center">Contact Form</p>
<p align="center">
Some content
</p>
</div>
The jQuery
code:
<script>
$("#target").keypress(function(){
var id = $(this).html().toLowerCase();
console.log('id is: '+id);
$('.current').fadeOut(900, function(){
$('#'+id).fadeIn(900);
$('.current').removeClass('current');
$('#'+id).addClass('current');
});
});
</script>
The code above doesn't work, i am new with jQuery
events, could you please guiding me to the right way.