> From: Dan Eastwell
> I'm also something of a newbie, but you can include normal 
> javascript in with jquery, as jquery *is* javascript.

That is a key point that everyone should memorize. jQuery *is* JavaScript.

> The main problem is that jquery functions won't work on 
> normal DOM objects, they have to be selected using the $ 
> function first e.g.
> $(#myObject).show();

That wouldn't work as is, of course. You probably meant:

$('#myObject').show();

But if you already have a DOM node reference in a variable, you can get a
jQuery object for it directly:

var foo = document.getElementById('foo');  // or whatever
$(foo).show();

> The $ function also gives you a selection of things to play 
> with (an array/node collection? Correct me if I'm wrong), so 
> it's difficult to straight apply DOM methods to them.

It's an array of DOM nodes. (More precisely, it's an array-like object with
[0], [1], ... and .length properties.)

Typically you use .each() to iterate over those, but you can also treat them
as an array like any other array:

$('#foo')[0]

is a reference to the first DOM node in the jQuery object - which should be
the DOM node whose ID is 'foo' - or undefined if there is no such node.

> The other problem with mixing the two is 'this', $(this) and 
> this are completely different - I've not quite got my head 
> round it yet!

Same principle applies here. 'this' isn't magic; it's just another variable
name as far as we're concerned here. If 'this' is a reference to a DOM node,
then $(this) gives you a jQuery object containing that DOM node. Building on
the example above:

$(this)[0] === this

-Mike

Reply via email to