On Wed, Jan 13, 2010 at 9:11 AM, olliewebster <ollie....@googlemail.com>wrote:

> Hi,
> I recently came across JQuery, but I'm not sure weather I should use
> it. Even though I already know JavaScript, would I have to learn a new
> language specific to JQuery? What would the advantages of using JQuery
> be? Finally, would it be hard to install?
> Thanks
>

I like to think I'm fairly competent ant JavaScript, and for the longest
time, I put off learning jQuery because really... why invest the time to
learn a different way to write stuff I already know how to write?

Then I saw this:

$('#element').toggle();

That right there is the same as:

if (document.getElementById('element').style.display == "none") {
     document.getElementById('element').style.display = "block";
} else {
     document.getElementById('element').style.display = "none";
}

As you can see, that's code to toggle the display of an element.  If it's
hidden, show it.  If it's visible, hide it.

Let's say you wanted to trigger that based on a button click.

Normally, you'd have <input type="button" id="myButton"
onclick="toggleElement();" />

In jQuery, your script is completely unobtrusive and should never show up in
the HTML itself.

In jQuery, that same click would be up int he script area:

<script>
     $('#myButton').click(function() {
          $('#element').toggle();
     });
</script>

So, as you can see... yes, it's taking the time to learn a new way to do
what you already know how to do... but it's a way that will save you a ton
of time.  I've changed the behaviors of HTML pages entirely without ever
touching the .html file (all done in the .js).

If it takes you a week to grok the basics (because you'll probably always be
"learning")... you'll make up that week in no time just by virtue of never
having to type document.getElementById() again :)

"Installing" jQuery is simply a link to the jQuery.js file.

If you're storing it locally, it's <script
src="my/path/to/jQuery.js"></script>.

You can also point to google's repository where they host the jQuery file
(as well as other libraries).

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
"></script>

Add the line above, and jQuery is "installed".  Go nuts :)

-- 
Charlie Griefer
http://charlie.griefer.com/

I have failed as much as I have succeeded. But I love my life. I love my
wife. And I wish you my kind of success.

Reply via email to