I'll take my shot at giving a crude and rough overview of the magic behind jQuery.
Javascript is somewhat of an after-the-fact editor in the sense that it change change or edit the html after the client has received it. Of course it can do much more, but lets focus on this for a moment. jQuery uses this knowledge to allow finding elements in the DOM/HTML very easy by using CSS style syntax. jQuery finds the elements and returns an object that is very similar to an array, but with many more functions and abilities attached. When one calls .addClass on the jQuery object, the library simply .map's the function across the array of elements. Ok now that we understand roughly that jQuery is an object storing an array of elements and a bunch of functions we can begin to look at what these functions are. The core of jQuery are a group of functions designed to create/edit/delete the array of elements. It also provides many methods of editing the basic components of elements like .css and .attr. But the true beauty of jQuery is it's ability to grow! By allowing the jQuery object to be extended via plugins anyone can add functionality to manipulating web pages. This includes tools from .ajax to .animate to .tabsto .newsticker, and the list continues on and on. That description was very abstract and didn't discuss how jQuery finds the elements in the page. So if you're feeling a little nerdy keep reading. Right at the top of jquery.1.1.2.js everything happens. jQuery creates itself and calls .find to get the elements and save them into an array. Boom, everything's done. The trick question is what happened when .find was called? As we continue to scroll down through the source code we see jQuery extending itself adding many useful functions like .pushStack and .each. But skip ahead to the real meat and bones of jQuery, search for: expr: Here was can see all the selection options that jquery uses along with the all-important regex that powers the parsing of the query. As we scroll a little further we see the find: and this is where everything happens, where jQuery actually looks for the elements. Study this code carefully if you wish to understand how exactly how jQuery works.