0

im just curious about this proper code. im happy if some can correct this and explain a little about this.

$('.parentmenu:nth-child(1)').addClass('on', function(){
    $(this+'ul').delay(500).slideDown();
});

I would like to use the same class element as for this referring and add UL element to trigger the navigation slide-down. I would like to know what is the correct format.

Or is there a way to shorten this code? Thanks in advance.

5 Answers 5

1

you can either

$('ul',this).delay(500).slideDown();

or

$(this).find('ul').delay(500).slideDown();

either should work.

Sign up to request clarification or add additional context in comments.

Comments

1

I have never heard .addClass() having any callbacks

This is a wrong syntax..

.addClass('on', function(){

Maybe you are looking for this

$('.parentmenu:nth-child(1)').find('ul').delay(500).slideDown();

Comments

1

I've never heard of a callback for addClass().

Try this instead:

$('.parentmenu').first().addClass('on').find('ul').delay(500).slideDown();

Comments

1

I dont think addClass accepts a callback. A readable line would be

$('.parentmenu').addClass('on')
                .children('ul').delay(500).slideDown();

Comments

0

yeah it works on single but not inside the addClass. so i refine my codes to this base on your answers.

$('.parentmenu:nth-child(1)').addClass('on').find('ul').delay('500').slideDown();

This fully worked out the child menu sliding down effect with the adding class on for parent menu hover activation.

Thanks for your help guys.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.