Do you have Firebug? If not, get it and enable the Console and Script tabs,
then enter these statements into the console input line, one at a time with
Enter after each one:

$("button")

$("button")[0]

$( $("button")[0] )

Each one will log an object to the console log. Click on each of these
objects to look at its properties.

You'll find that the first one is a jQuery object - which happens to be an
array of DOM elements. Take the [0] of that object, as in the second
expression, and now you have the first DOM element in that array. Since it's
not a jQuery object, it doesn't have a .bind() method. Instead, it has the
properties and methods of any other DOM element.

Now wrap the whole thing in another $() function call, as in the third
expression, and you're creating a new jQuery object that happens to contain
the same DOM element as the first one.

-Mike 

> From: bittermonkey
> 
> I'm fairly new to the framework and I've been messing around a bit.
> These below confuses me.
> 
> 1.  Why is this snippet not working?  Firefox's error console 
> throws an error saying < $("button")[0].bind is not a 
> function > $("button")[0].bind("click", function(event){alert(this)});
> 
> 2.  And why does this work?
> $($("button")[0]).bind("click", function(event){alert(this)});
> 

Reply via email to