views:

438

answers:

4

On my website, I use some simple jQuery to slide down and up an existing element.

$('#menu li:first strong').bind('click', function() {

            var searchBox = $(this).parent().find('form');

            if (searchBox.is(':hidden')) {
                //$('#menu #advanced-search-block').hide();
                searchBox.slideDown(1000);

            } else {

                searchBox.slideUp(1000);
            }

        });

Inside of the parent <li> element are some elements of which their CSS is set to display: none. When I click the element to trigger this event, the hidden elements appear. I have tried using the commented out code to remedy this (which it does), but I am thinking there should be a more elegant solution. I know you can use .stopPropogation() on events, so is there anything you can do to make slideDown() stop making child elements with display: none visible?

Edit

Sorry about the lack of HTML guys. There is a fair bit of HTML around these elements, and I didn't want to post a huge amount of it. You can access the work in progress here: http://www.noosanativeplants.com.au/~new/ (If someone wants to post the offending markup, it would help other people in the future who find this question). Thank you

A: 

What sort of elements are hidden? I have a div with this css set and it isnt showing up when I toggle the visibility of its parent div.

Pete
I posted a link. Thanks
alex
from glancing at the question it seems like your problem area was the advanced search section on the slideDown for the fist buttonin the upper left, right? for me the advanced search stays hidden until i select the option for it specifically. isn't this what should happen? Am I missing something?
Pete
I think this is happening only because of my apparent 'work around'. Maybe I'm just confused, and it's expected behaviour of jQuery. Anyway, thanks for looking into it :)
alex
A: 

I believe the way you are doing it is the only way. Also, I don't think that it is a jQuery issue specifically. The hidden attribute (just like opacity) will affect all children in the DOM tree, and thus when you show 'searchBox' it will show all inside elements. Picking the elements to hide at the same time you're sliding up will never show those elements.

Scott M.
I posted a link. Thanks
alex
A: 

Your jQuery looks good, as for the invisible elements you could define your own css class to explicitly hide the elemnts so that hide()/show() have no effect and use addClass()/removeClass()

Chad Grant
A: 

Something like this, maybe?

$(this).filter(':not(>*)').slideDown(1000);

I'll try it in FireBug on your site and see if it works.

Edit: Nope, it doesn't. :-( Not sure what else to suggest other than what you've got.

KyleFarris
That might make everything slide down invidiously though.. not as a whole. Thanks but.
alex