> if I need the Dom node and jQuery object on the same function 
> should I give each different variables or is there a workaround ?

Given a jQuery object, you can always get directly to its DOM node(s) with
[0], [1], etc. So you don't *need* another variable, but you can always use
one if you want.

I do this quite often, when I'm using a jQuery selector that I know will
return only a single DOM node, e.g. an ID selector like this:

    var $foo = $('#foo'), foo = $foo[0];
    // $foo is a jQuery object, foo is the matching DOM node.
    // These should alert the same value:
    alert( $foo.html() );
    alert( foo.innerHTML );

I also do this the other way around when I have a DOM node to start with.
Suppose I have a function that takes a DOM node as an argument:

    function test( element ) {
        var $element = $(element);
        // $element is the jQuery object
        // element is the DOM node
    }

In both cases I use the convention of $xyz for the jQuery object and just
plain xyz for the corresponding DOM object. This lets me see when reading
the code that they are closely tied together, while still making it easy to
tell them apart.

-Mike

Reply via email to