Search code examples
javascriptjquerydomtoggle

How to toggle a function for multiple divs at once?


I previously got this (useful!) answer about using .next() for a DIV "blinds" toggling effect.

However, I can't seem to get this simple function to work for more than one DIV at the same time:

$(document).ready(function () {
    $("#closeButton").click(function () {
        $(this).next().toggle("fast");
    });
});

Any ideas?


Solution

  • The selector you are using is only selecting one element. You would need to change is to it selected a collection of elements.

    $(document).ready(function () {
        $(".wider_div h3").click(function () {
            $(this).next().toggle("fast");
        });
    });
    

    This might work given the structure.