tags:

views:

52

answers:

1

Hello there, I am using the toggle function from jQuery and for some reason is not working, this is what I have:

    $(document).ready(function(){

            var flip = 1;
            $("#tg1").click(function () {
            $("#tg1-contenido").toggle( flip++ % 2 == 0 );
            });​
}

I don't know what I am doing wrong, any help would be greatly appreciated. Thanks!

+4  A: 

It looks like you want every other click to toggle it's visibility, in which case you can just use .toggle() without parameters, like this:

$("#tg1").click(function () {
  $("#tg1-contenido").toggle();
});

This will hide it if it's shown, and show it if it's hidden.

Also, I'm assuming your code got cut off, but make sure you're closing your document.ready wrapper correctly, that last line with only } should be a });.

Nick Craver
Yes, I do have }); at the end, I'm sorry. It is still now working though
fgualda87
@fgualda87 - If this isn't working, you most likely have a JavaScript error, check your console!
Nick Craver
Yes, it is working perfectly now! Thank you very much!!
fgualda87
Hey Nick, if I wanted to start with a hidden row. Like I want the first row of a table to be hidden, and when I click a button it should appear, so I'm using toggle. How do I make it hidden by default??
fgualda87