SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple swap divs with jquery

    hi guys,
    the script below swaps the divs based on the ID, however when I have up to 5 divs, how do I implement it ?

    Or do I repeat the triggerButton event over and over again ?

    e.g. $('#triggerButton').click(function (e)
    then $('#triggerButton1').click(function (e)
    $('#triggerButton2').click(function (e)

    etc ???


    Here is my code
    Code:
    $(document).ready(function () {
        $('#triggerButton').click(function (e) {
            e.preventDefault();
            $('#div1').fadeOut('fast', function () {
                $('#div2').fadeIn('fast');
            });
        });
    
    });
    many thanks
    Ehi

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,055
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Could you post some HTML to go with that code.
    I'm finding it quite hard to get a picture of what you're trying to do.

  3. #3
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, I found an easy way to get it done. Adding the same class to multiple divs.
    many thanks
    Code:
    $(document).ready(function () {
       
        $('.showSingle').click(function () {
            $('.dashboard_adverts').fadeOut();
            $('#div' + $(this).attr('target')).fadeToggle(1500);
        });
    
    });


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •