0

I'm simply trying to make a button display when it's click. I'm fairly close, can anyone give me some advice on how to improve it, so it'll work?

jQuery

$(document).ready(function (){
    if( $("#btn").css('display', 'none') ) {
        $("#btn").click(function() ) {
            $("#info").css('display', 'block');
        )};
    } else { 
      $("#info").css('display', 'none'); 
    }       
});

    <div id="btn">
        <a class="help-a" href="#">help</a>
    </div> 
    <div id="info">
        <p>data goes here</p>
    </div>

Thanks

nickhiebertdev
  • 525
  • 1
  • 6
  • 21

2 Answers2

4

You are looking for $.fn.toggle method: show if hidden, hide if visible:

$(document).ready(function () {
    $("#btn").click(function () {
        $("#info").toggle();
    });
});
dfsq
  • 191,768
  • 25
  • 236
  • 258
0
$(document).ready(function (){

        $("#btn").click(function() ) {
             if( $("#btn").css('display') === "none" ) {
                   $("#info").css('display', 'block'); 
             } else { 
                   $("#info").css('display', 'none'); 
             }       
        )};

});

You were doing it right - Just minor code re-arrangement and a small update was needed.

Nikhil Aggarwal
  • 28,197
  • 4
  • 43
  • 59