I made a plugin called toggleText. I want to chain this to a jquery object and toggle the text. I also want to add a click event to the jquery object. If I just use the toggleText plugin, it works. But if I also add the click handler, I get the following error:
Error: $("#toggleError").toggleText("Show Error", "Hide Error") has no properties Using just the toggleText handler or the click handler by themselves works. Any ideas? Here is the code snippet. //This one works w/0 the click handler function showError(request, statusText){ $("#failure").html(request.responseText); //this works $("#toggleError").toggleText("Show Error", "Hide Error") } //this one fails. function showError(request, statusText){ $("#failure").html(request.responseText); //this does not (added click event to the chain) $("#toggleError").toggleText("Show Error", "Hide Error").click( function(){ $("#failure").show(); } ) } //plugin jQuery.fn.toggleText = function (evalText1, evalText2){ $(this).html(($(this).text() == evalText1)?evalText2:evalText1); }