Mix and match at will.  But just like traditionaly JavaScript, you'll 
need to take care to be dealing with the right objects, and that those 
objects exist when you reference them.

One way to mix in jQuery is the use of it's array of matched elements. 
When you do $("#myelement"), you get an array of objects that match your 
selector.  You can utilize this if you'd like by including the array 
index:

   alert ( $("#myelement")[0].innerHTML );

The element in the array is the exact same element you would get with a 
getElementById().

The "this" issue is always confusing because "this" is always context 
sensitive.  But the general rule of thumb is that if you think using 
"this" is the right choice in your code, do so, but you can get the 
additional jQuery features by wrapping your element reference (the 
"this" keyword in the jQuery method.  i.e.

   alert ( this.id );
   alert ( $(this).attr("id") );

These both result in the same thing.

You could also mix things by using your traditional object references:

   var mydiv = document.getElementById("theDiv");
   $( mydiv ).slideDown();

Anytime you have a native DOM object reference, you can wrap it in the 
jQuery object and have access to everything jQuery brings to the table.

When you get down to it, there will always be some situations where 
native JavaScript is faster (in terms of writing the code, or even in 
terms of performance).  You'll end up applying your native JavaScript 
skills anyways.  You still use the same IF statements, the same FOR 
loops, and everything else.  jQuery just simplifies a great deal of our 
tasks... :)

HTH.

Shawn

Dan Eastwell wrote:
> Hi Jon,
> 
> I'm also something of a newbie, but you can include normal javascript
> in with jquery, as 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();
> 
> 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.
> 
> 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!
> 
> That's a start, give it a go and read some of the tutorials -
> otherwise if you have a specific problem that arises, post that!:)
> 
> Thanks,
> 
> Dan.
> 
> On 1/13/08, Jon Moses <[EMAIL PROTECTED]> wrote:
>>  I have looked on the jQuery website but I just wanted some extra
>> advice from people building plugins.
>>
>> Can I just mix any vanilla javascript in with jQuery? What are the
>> basic rules?
>>
>> I am a newbie to javascript and am currently doing my best to keep up
>> with jQuery at the same time but need a bit of extra advice
>>
>> Thanks all
>>
>> Jon
>>
> 
> 

Reply via email to