Search code examples
javascriptjqueryhtmlcsschildren

Invoke child element event


I need to invoke a function (toggleslide) on child div element with class name pane (parent div is flip).

I have a parent div and onclick I need a parent div element to show (slide) some content in child div. When I click on the div it will show all divs with child class pane so i tried add this to 3rd row $(".flip, this").children(".pane").slideToggle("fast") but it does not work at all.

$(document).ready(function(){
   $(".flip", this).click(function(){
        $(".flip").children(".pane").slideToggle("fast");
    });
});

Thanks for any help in advance


Solution

  • From your description it sounds like you want to only call slideToggle() on the .pane elements within the clicked .flip. In that case you do need to use this, but you need to use it as the primary selector within the click handler. Try this:

    $(document).ready(function(){
       $(".flip").click(function(){
            $(this).find(".pane").slideToggle("fast");
        });
    });