tags:

views:

44

answers:

1

how can i change this: (this script says that it should hide #writeComment if #tryout is checked )

$('#tryout').click(function () {
  $('#writeComment').toggle(!$(this).attr('checked'));
});

Now i dont want to have a checkbox that you check, but instead this link

<a id="tryout">Click to vote</a>

so then when you click on this "link", #writeComment hides...

+5  A: 

You can use .toggle() without a boolean, like this:

$('#tryout').click(function() {
  $('#writeComment').toggle();
});

Just set the display state to what you want it to be initially, internally .toggle() checks if it's :visible, and if it is, calls .hide(), otherwise it calls .show().

Nick Craver
+1 fast fingers
gnarf
really fast, thank you.. i was trying to make a fadein $('#writecomment').fadeIn('slow', toggle()); seems like i dont understand nothing of jquery..
Karem
@Azzyh - For a fade toggle, do `.animate({ opacity: 'toggle' });` :)
Nick Craver