jQuery Overview - Library Components
(Page 2 of 4 )
Let's look at the different components available within jQuery to get an idea of exactly what we can achieve when using it. The core of the library sets up the $ object and allows you to easily select elements based on id, class name, element name or other, more complex requirements.
The core section of the library also allows you to quickly and easily create new elements by passing raw HTML to the $ object. So if you need to insert a new paragraph into your page, it can be created with just:
$("<p>")
Once created, you can add content to it, add styles or attributes, and then add it to the page in your desired location using one of the many jQuery methods, all in a consistent, cross-browser way.
JQuery's equivalent to onDomReady (or similar) can also be found here in the core section of the library, and like the rest of the library, it's beyond easy to use. All you need to do is wrap any code within the following function:
$(function() {
//your code here
});
The code within the anonymous function will only be executed when the DOM is in a usable state. It also shields you from littering the global namespace, as any variables declared here will become properties of the jQuery $ object instead of the window object.
Next: Attributes >>
More JavaScript Articles
More By Dan Wellman