jQuery Basic FAQ Plugin Demo

Frequently Asked Questions
+How do I select an item using class or ID?

This code selects an element with an ID of "myDivId". Since IDs are unique, this expression always selects either zero or one elements depending upon whether or not an element with the specified ID exists.

+How do I select elements when I already have a DOM element?

If you have a variable containing a DOM element, and want to select elements related to that DOM element, simply wrap it in a jQuery object.

+ow do I test whether an element has a particular class?

.hasClass() (added in version 1.2) handles this common use case: