I'm trying to understand jQuery, but I'm hindered by the syntax looking so strange to me. I don't even understand how a regular JavaScript parser parses it! I can read sample code and I'll understand from the accompanying material what it's doing, but I don't understand how.
I understand that $
is just an alias for jQuery, but that doesn't answer the question. Take the classic jQuery function used to delay things until the page is fully loaded:
$(document).ready(function() {
...
});
or a jQuery selector that selects all p
elements in the DOM and applies a CSS rule:
$('p').css('color', 'blue');
So... somehow document
and 'p'
are recognized as keys, and associated with the appropriate values, right? Except that doesn't seem like it could be true, because then jQuery would have to pre-calculate the results it was going to return for any possible key it could be asked for, including element ids that jQuery probably couldn't know about! So how on earth does it really work?
(edited to fix an error in describing code)
.addClass()
).