Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts

    This MUST be an easy fix...?

    Hi--

    I am using the following js to click on divA to fade out divB, and then click on divA again to fade in divB. It works the first time, but not the rest.

    My apologies for the terrible script (I know nothing about js), but could someone help me fix this? MANY THANKS FOR ANY HELP!

    $(document).ready(function(){
    $('#divA').click(function() {
    $('#divB').fadeOut(500, function() {
    $('#divA').click(function() {
    $('#divB').fadeIn(500);
    });
    });
    }); });

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    you improperly nested your functions and had an extra });

    Code:
    $(document).ready(function () {
        $('#divA').click(function () {
            $('#divB').fadeOut(500);
        });
        $('#divA').click(function () {
            $('#divB').fadeIn(500);
        });
    });

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi, DanInMa--

    Thanks for the reply. Unfortunately, the new code just fades out and then fades in divB. If possible, I would like it to do both as separate actions triggered by clicks, as described above.

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    $('#divA').toggle(function () {
      $('#divB').stop().fadeOut(500);
    }, function () {
      $('#divB').stop().fadeIn(500);
    });
    The jQuery docs for toggle seem to be wrong.. that is, the wrong way round

    handler(eventObject)A function to execute every even time the element is clicked.
    handler(eventObject)A function to execute every odd time the element is clicked.
    Last edited by AndrewGSW; 12-31-2012 at 12:29 AM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #5
    New Coder
    Join Date
    Aug 2011
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thanks!

    Thanks, AndrewGSW--That did the trick!!!!!!! Is that cross-browser?

  • #6
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Quote Originally Posted by eabigelow View Post
    Thanks, AndrewGSW--That did the trick!!!!!!! Is that cross-browser?
    Well, it's jQuery, so.. yes.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #7
    New Coder
    Join Date
    Aug 2011
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts

    thanks again

    Great. Thanks again!


  •  

    Posting Permissions

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