user2096890
user2096890

Reputation: 159

Using JQuery to toggle a div

I am new to JQuery and I am having some trouble getting my code to work just right. For some reason my JQuery is hiding the link (a) element. I need the link to toggle the 'wrap' div. What could I be doing wrong?

JQuery:

$(document).ready(function() {
   $('.wrap').hide();
   $('.open').toggle(
      function() {
     ('.wrap').show();
  },
  function() {
     ('.wrap').hide();
      }
   ); // end toggle
}); // end ready

JSFIDDLE

Upvotes: 2

Views: 309

Answers (2)

zerkms
zerkms

Reputation: 255085

http://jsfiddle.net/AbXYp/4/

$('.wrap').hide();
$('.open').click(function() {
    $('.wrap').toggle();
    return false;
});

So on every "Notifications" link click you're toggling the .wrap

The real roots of the issue with your code: The .toggle() event handler was REMOVED in jquery 1.9 -- http://api.jquery.com/toggle-event/, so what you're using in your code sample is animation method http://api.jquery.com/toggle/

Upvotes: 8

Jinal Shah
Jinal Shah

Reputation: 315

Just replace your jquery with

$(document).ready(function() {
 $('.wrap').hide();
    $('.open').click(function(e){e.preventDefault();$('.wrap').toggle();return false;}); // end toggle
}); // end ready

It should work

Upvotes: 0

Related Questions