Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-30-2012, 05:40 PM   PM User | #1
eabigelow
New Coder

 
Join Date: Aug 2011
Posts: 33
Thanks: 1
Thanked 0 Times in 0 Posts
eabigelow is an unknown quantity at this point
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);
});
});
}); });
eabigelow is offline   Reply With Quote
Old 12-30-2012, 07:38 PM   PM User | #2
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
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);
    });
});
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 12-30-2012, 11:23 PM   PM User | #3
eabigelow
New Coder

 
Join Date: Aug 2011
Posts: 33
Thanks: 1
Thanked 0 Times in 0 Posts
eabigelow is an unknown quantity at this point
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.
eabigelow is offline   Reply With Quote
Old 12-31-2012, 12:26 AM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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.
__________________
"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

Last edited by AndrewGSW; 12-31-2012 at 12:29 AM..
AndrewGSW is offline   Reply With Quote
Old 12-31-2012, 12:33 AM   PM User | #5
eabigelow
New Coder

 
Join Date: Aug 2011
Posts: 33
Thanks: 1
Thanked 0 Times in 0 Posts
eabigelow is an unknown quantity at this point
Thanks!

Thanks, AndrewGSW--That did the trick!!!!!!! Is that cross-browser?
eabigelow is offline   Reply With Quote
Old 12-31-2012, 12:46 AM   PM User | #6
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Old 12-31-2012, 12:48 AM   PM User | #7
eabigelow
New Coder

 
Join Date: Aug 2011
Posts: 33
Thanks: 1
Thanked 0 Times in 0 Posts
eabigelow is an unknown quantity at this point
thanks again

Great. Thanks again!
eabigelow is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:02 AM.


Advertisement
Log in to turn off these ads.