Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6781827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:40:12+00:00 2026-05-26T16:40:12+00:00

Well it seems I know enough Javascript to hurt myself so I come asking

  • 0

Well it seems I know enough Javascript to hurt myself so I come asking help from you guys here. Here is what I am attempting to do and my issue.

I have two forms and only one will be filled out depending on the users choice. They will click one button or the other. When they click the button the form fades in and the button changes classes (goes from a light button to a dark button) Here is were I am running into issues. First I cannot get the form to fade in at all and the buttons will only change classes if I click them twice not once.

One other thing I am not sure how to go about is if I have say form 1 chosen but I meant to click form 2 then I want form one to fade out, form 2 to fade in and the buttons change accordingly. Here is my Code:

JS

<script type="text/javascript">
var $j = jQuery.noConflict();
var $jtest1 = $j('#test1'); 
var $jtest2 = $j('#test2');

$j("#button1").live('click',function(){  
    //Fade out form if shown and fade in form selected
    $jtest2.fadeOut("slow", function(){
         $jtest1.fadeIn("slow");
    });
    $j('#button1').live('click', function(){
        //change class from light to dark
        $j(this).addClass('dark_button').removeClass('light_button');
    }); //I need to change this class to light if
        // button 2 is selected and change button 2 to dark
});
</script>

HTML

<p class="light_button" id="button1">Test 1 </p>
<p class="light_button" id="button2">Test 2 </p>


<div class="hide" id="test1"><p>TEST</p></div>
<div class="hide" id="test2"><p>TEST 2</p></div>

Note: class="hide" is style="display:none"

Thanks for any help because I am a but stuck and not sure to go about this. Also please give me an example because I do not always follow when someone say change this to that etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:40:12+00:00Added an answer on May 26, 2026 at 4:40 pm

    Look at the code below, added comments on why

    $j("#button1").live('click',function(){  
        //Fade out form if shown and fade in form selected
        $jtest2.fadeOut("slow", function(){
             $jtest1.fadeIn("slow");  
        });
    
        //The following is inside the click so I do not get added until the first click 
        //and added after every click so I multiply! 
        //Hence why it takes 2 clicks
    
        $j('#button1').live('click', function(){
            //change class from light to dark
            $j(this).addClass('dark_button').removeClass('light_button');
        }); //I need to change this class to light if
            // button 2 is selected and change button 2 to dark
    });
    

    You should be doing something like this

    $j("#button1, #button2").live('click',
        function(){  
    
            //figure out what button was clicked. 
            if(this.id === "button1"){
                var btnA = $j(this);
                var btnB = $j("#button2");
                var divA = $j('#test1');
                var divB = $j('#test2');
            }
            else{
                btnA = $j(this);
                btnB = $j("#button1");
                divA = $j('#test2');
                divB = $j('#test1');
            }
    
            //make sure it is not already active, no use to show/hide when it is already set
            if(btnA.hasClass('dark_button')){
                return; 
            }
    
            //see if div is visible, if so hide, than show first div
            if(divB.is(":visible")){        
                divB.fadeOut("slow", function(){
                     divA.fadeIn("slow");
                });
            }
            else{//if already hidden, just show the first div
                divA.fadeIn("slow");            
            }
    
            //Add and remove classes to the buttons to switch state
            btnA.addClass('dark_button').removeClass('light_button');
            btnB.removeClass('dark_button').addClass('light_button');
        }    
    );
    

    jsfiddle example

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, it seems simple enough, but I can't find a way to add a
It seems I don't understand javascript callbacks quite as well as I thought. In
Well is there? From everything I've read, it seems like the answer is no,but
The question seems pretty well formulated I have a virtual machine which implements only
It seems to be well-known there is a bug when using JMenuItem.getRootPane(). I read
It seems to me that it would work perfectly well to do tail-recursion optimization
does FastCGI work well with PHP? It seems that some people running Ruby on
cgi.escape seems like one possible choice. Does it work well? Is there something that
I understand PCRE pretty well, but MySQL's regular expression flavor seems to get the
The article in Wikipedia seems too verbose. I understand framework as a well designed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.