- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › A beginner question in jquery.
Hi,
I m creating a dropdown menu with jquery which is working fine on two clicks however if you click on the link the third time if slides up and down itself. Can you tell me what mistake I m making and how to fix this. I dont want to add any more classes or ids in the markup. I m new to jquery so an explanation would be very helpfull.
here is the code..
$(document).ready(function(e) {
$('.sidebar li ul').hide();
});
$('.sidebar li').click(function(){
$(this).addClass('active');
$('.active ul').slideDown(700);
$('.active').click(function(){
$('.active ul').slideUp(700);
$('.active').removeClass('active');
});
});
Thanks jshjohnson for writing the codepen and thanks a lot JoshBlackwood , but since I m learning jquery , if you could please explain a little(in my script) WHY when you click on the link third time it slides up and down itself , would very helpfull for me to understand.
You are awesome Josh , you explained that really well, now I have a better understading of it, all thanks to you. And I have one more question in javascipt but I’ll create a new thread for it.