0

Problems with JavaScript add/remove class on button click. It just won't perform the function.

Read through a number of stack overflow solutions, none worked for this particular situation.

These are the elements:

// CSS 

.hideWelcome{
    display: none;
}

.autoHide {
    display: none;
}

// JavaScript Hide Welcome

  $(document).ready(function() {    
      $("#showFormBtn").live("click", function() {
        $("#WelcomeDiv").toggleClass("fadeOutUp animated hideWelcome");
        $("#formInput").toggleClass("autoHide");
    });
 });


    // Welcome Div

    <div class="container">
        <div class="row">
            <div id="WelcomeDiv" class="one-half column fadeInUp animated" style="margin-top: 25%">
                <h4>Make a Difference</h4>
                <p>Volunteer today!</p>
                <div class="bounceIn animated">
                <input type="button" id="showFormBtn" name="showFormBtn" class="button button-primary" value="Sign Up"/>
                </div>
            </div>

    // Div to show

            <div id="formInput" class="one-half column fadeInUp animated autoHide" style="margin-top: 25%">
                <h4>HELLO YA'LL</h4>
                <p>Howdy!</p>
                <div class="bounceIn animated">
                    <input type="button" id="showFormBtn" name="showFormBtn" class="button button-primary" value="Sign Up"/>
                </div>
            </div>
        </div>
    </div>
1
  • Glad the solution worked. Would you mind accepting this answer? It might help people experiencing a similar issue and will help getting your question noticed Commented Feb 10, 2016 at 4:33

1 Answer 1

1

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers.

Try this:

$("#showFormBtn").on("click", function() {
  $("#WelcomeDiv").toggleClass("fadeOutUp animated hideWelcome");
  $("#formInput").toggleClass("autoHide");
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.