views:

67

answers:

3
+2  Q: 

jQuery toggle();

Hi

I am loading data dynamically by AJAX into a cluetip (http://plugins.learningjquery.com/cluetip/#).

I want to toggle the results from a link like so:

$(document).ready(function() {
    $("#calendarLink").live("click",( function() {
        $("#result").toggle();
    }));
});

For some reason the above will not work. Can you suggest an alternative?

+1  A: 

Couple of questions/points

Do you really need to use .live() You're using an ID selector, so there should only ever be one of these.

Also, you have an extra set of brakets. Probably not a problem, but you could remove them:

$(document).ready(function() {
    $("#calendarLink").click( function() {
        $("#result").toggle();
    });
});
James Wiseman
Tried the code but get same result. Toggle not working very strange.
factoringcompare
Suppose I don’t need the .live function but either way it doesn’t work
factoringcompare
Can you post your HTML as well, and add a comment below when you've done this so it shows up for me.
James Wiseman
A: 

Perhaps the toggle() function isn't be used properly?

See here http://api.jquery.com/toggle/

I'm not sure if this is new functionality only for jQuery 1.4 but it appears the toggle function requires parameters.

Ryan
No, Toggle should be ok
James Wiseman
A: 

The following code is correct (demo online - http://jsbin.com/ehate/edit):

$("#calendarLink").live("click", function(e){
  $("#result").toggle();
});

You use $.live() only if #calendarLink will be added dynamically later. If it isn't, use a regular click:

$("#calendarLink").click(function(e){
  $("#result").toggle();
});

If this is not working for you, be sure to check your #calendarLink and #result elements in your HTML. Make sure the ID values are correct. Mainly, be sure your casing is correct.

Jonathan Sampson