-1

How can I show .quick-links-container on button click?

jsFiddle: http://jsfiddle.net/gnjNq/5/

I had display: none; set but I took it off so you can see the container.

So far I have this but its not working:

$('.quicklinks-button').click(function(){$('#quick-links-container').show();});
Chaddly
  • 267
  • 1
  • 6
  • 18
  • Try here http://stackoverflow.com/questions/1403615/use-jquery-to-hide-a-div-when-the-user-clicks-outside-of-it –  Jul 02 '13 at 14:38

5 Answers5

2

You forgot to add the jQuery library on the jsfiddel at the left panel.

Also, you were using an id (#) selector instead of a class selector (.) for quick-links-container.

Try this:

$('.quicklinks-button').click(function(){
    $('.quick-links-container').toggle();
});

Living example: http://jsfiddle.net/gnjNq/9/

Alvaro
  • 40,778
  • 30
  • 164
  • 336
1

Your element has that as a class, not an id, you want to show and hide so you need toggle, your fiddle didn't have jQuery added.

$('.quicklinks-button').click(
    function () {
        $('.quick-links-container').toggle(1000);
    }
);

DEMO

Paul S.
  • 64,864
  • 9
  • 122
  • 138
0

try this

demo

$('.quicklinks-button').click(function(){$('.quick-links-container').show();});

.quick-links-container{
right: 20px;
background-color: white;
height: 500px;
width: 200px;
position: absolute;
box-shadow:5px 1px 6px rgba(0,0,0,.2);

}
Arun Kumar
  • 1,607
  • 1
  • 18
  • 33
0

You didn't succeed because of following reasons:

  1. You didn't include the jQuery in your example file.
  2. You have a class called quick-links-container in your HTML but in your JS you are using #quick-links-container which returns an ID. So that needs to be changed to '.quick-links-container'
  3. You are using only show() on click therefore on click the div will always be set to show, instead you can use toggle() to toggle the visibility of the div.

So, your javascript code needs to be modified to following:

$('.quicklinks-button').click(function(){ $('.quick-links-container').toggle();});

jsFiddle: http://jsfiddle.net/GautamChadha/U5Rwg/

Gautam Chadha
  • 306
  • 1
  • 6
0
// you must use toggle
// this is jquery 

$('#hide').click(function(){
var current = $(this).val();
$('p').toggle();

// this will toggle the value of button from show to hide and vice versa

if(current == 'hide'){                
$('#hide').val('show');
}else{
    $('#hide').val('hide');
   }

});
sid
  • 97
  • 12