1

I want a simple effect of slide up and down. I'm new to jquery and I tried th following code, but it's not working

<script> $(document).ready(function() { $('#fade li:first-child').css('display','none'); $('#fade li:second-child').click(function() { $('#fade li:first-child').slideDown(); }) }) </script> 

Html

<ul id="fade"> <li>one</li> <li>two</li> <li>three</li> </ul> 

Please help, thanks

4 Answers 4

2

error in this line:

$('#fade li:second-child') 

use :nth-child(2) selector to fetch 2-nd element or $('#fade li').eq(1)

<script> $(document).ready(function(){ $('#fade li:first-child').css('display','none'); $('#fade li:nth-child(2)').click(function(){ $('#fade li:first-child').slideDown(); }) }) </script> 
Sign up to request clarification or add additional context in comments.

Comments

0

try this code

 $(document).ready(function(){ $('#fade li:first-child').css('display','none'); $('#fade li').click(function(){ $('#fade li:first-child').slideDown(); }) }) 

Comments

0

Give this a go:

$(document).ready(function(){ var mySlider = function( toggle, obj ) { toggle.click(function(e){ if( !obj.is( ':visible' ) ) { obj.slideDown(); } else { obj.slideUp(); } }); } var slide_toggle = $('#fade li:nth-child(2)'); var menu = $('#fade li:first-child'); menu.css( 'display', 'none' ); mySlider( slide_toggle, menu ); }); 

Comments

-1

Are you missing <script type='text/javascript'> I did not found anything wrong with your code.

2 Comments

I think he wants it to slide up and down on click events.
hi there is no pseudo class :second-child in child selectors therefore your answer is wrong.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.