Yes - since what you did will only work with one element (in fact,
it'll break when there's more than one element), whereas Jonathan's
will work with any number of elements, and still return the correct
result set.

--John

On 5/2/07, Ariel Jakobovits <[EMAIL PROTECTED]> wrote:
>
> Jonathan, are you sure he shouldn't just use:
>
> jQuery.fn.toggleText = function (evalText1, evalText2){
>
>       $(this).html(($(this).text() ==
> evalText1)?evalText2:evalText1);
>
>        return this;
>
> }
>
> ----- Original Message ----
> From: Jonathan Sharp <[EMAIL PROTECTED]>
> To: jquery-en@googlegroups.com
> Sent: Wednesday, May 2, 2007 11:51:25 AM
> Subject: [jQuery] Re: Chaining methods
>
>  //plugin
>        jQuery.fn.toggleText = function (evalText1, evalText2){
>                        $(this).html(($(this).text() ==
> evalText1)?evalText2:evalText1);
>        }
>
> jQuery.fn.toggleText = function(txt1, txt2) {
>        return this.each(function() {
>            $(this).html( $(this).text() == txt1 ? txt2 : txt1 );
>        });
> }
>
> Cheers,
> -js
>
>
>
> On 5/2/07, Buzzterrier <[EMAIL PROTECTED]> wrote:
> >
> > 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);
> >        }
> >
> >
>
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery (English)" group.
To post to this group, send email to jquery-en@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jquery-en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to