Will Hunter
Will Hunter

Reputation: 29

Add/remove class on button click

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>

Upvotes: 0

Views: 283

Answers (1)

shu
shu

Reputation: 1956

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

Upvotes: 1

Related Questions