CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   This MUST be an easy fix...? (http://www.codingforums.com/showthread.php?t=285033)

eabigelow 12-30-2012 05:40 PM

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);
});
});
}); });

DanInMa 12-30-2012 07:38 PM

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);
    });
});


eabigelow 12-30-2012 11:23 PM

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.

AndrewGSW 12-31-2012 12:26 AM

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 :)

Quote:

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.

eabigelow 12-31-2012 12:33 AM

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

AndrewGSW 12-31-2012 12:46 AM

Quote:

Originally Posted by eabigelow (Post 1303140)
Thanks, AndrewGSW--That did the trick!!!!!!! Is that cross-browser?

Well, it's jQuery, so.. yes.

eabigelow 12-31-2012 12:48 AM

thanks again
 
Great. Thanks again!


All times are GMT +1. The time now is 02:29 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.