jQuery basics
I'm finally starting to teach myself how to use the jQuery JavaScript library.
So I'm looking at some of the tutorials on the Tutorials page.
And they all dive right into a mysterious notation using dollar signs and parentheses that doesn't match anything I've seen in JavaScript before.
So in case anyone else is in the same boat:
The fundamental piece that the tutorials don't bother to mention at the start, and without which you may have a hard time understanding the examples, is explained on the jQuery()
reference page.
As I understand it, the gist of it (bearing in mind that I'm new to this too, and that I'm somewhat oversimplifying) is this:
- The mysterious-looking
$()
is just a shorthand/synonym forjQuery()
. jQuery()
is a constructor for ajQuery
object.jQuery(selector)
(where selector is a CSS selector) “searches through the DOM for any elements that match the provided selector and creates a newjQuery
object that references these elements.”jQuery(html_fragment)
creates a new DOM element containing the specified HTML, then creates ajQuery
object that refers to the new element.
It's really not that complicated. But by saying that they're starting from scratch and then throwing $(foo)
constructions at the reader immediately, without explanation, the tutorials are doing readers a disservice.
I know, I know, instead of posting publicly about it, I should go contact the owners of the tutorials and ask them to add a note about this. I'll probably do that too. I'm just in a bad mood and am being easily annoyed. (I keep running into things in various contexts and on various sites today that are unclear or confusing or otherwise need fixing, so my patience is wearing thin.)
P.S. added a bit later: The Tutorials main page has edit links on it, so I thought maybe I could just go and fix things myself. No such luck. It turns out you need to log in first. How do I log in? Turns out you need to create an account first. Makes sense; how do I create an account? Oh, okay, there's a link that says “Log in / create account.” So I clicked that. Nope, it just gives you a login prompt. After about five minutes of increasing frustration, I finally went and asked on the IRC channel. Someone on the IRC channel answers that you can't create an account. And then quits the channel seconds later, before I can ask for clarification.
SO WHY DOES THE LINK SAY CREATE ACCOUNT?????
Gah.
If any jQuery people happen across this entry, I would love to talk with someone about improving the new-user experience on your site; drop me a note in email if you're interested in some suggestions.
P.P.S. added a bit later: I went to file a bug about the account creation thing.
And Akismet rejected my bug as spam.
It offered me a CAPTCHA.
Which I answered correctly.
And it not only re-rejected it as spam, but it stopped even offering me CAPTCHAs for subsequent attempts at filing bugs.
I finally managed to file a bug asking for help filing bugs, but only by giving my email address as “anonymous.”
This has been the single most frustrating new-user experience I have ever had. I'm sitting here yelling at my computer.
Not so sure I want to learn jQuery any more.