Enter jQuery, and I could not be happier. The core feature of jQuery is that you can select elements in your document by xpath or CSS-style selectors. This alone is well worth the price of entry. For instance, originally I had to do a "
document.getElementById("timebar")", use "
.getElementsByTagName("div")" on that, and then check each element's class as I looped through them to remove a class. Now I just write: "
$("#timebar .selentry").removeClass("selentry")". That's an if statement, a loop and a lot of long DOM method names I didn't need.
jQuery gives you all sorts of additional nice things - most of which I haven't tried yet. It includes:
- Easy creation and insertion of new elements into your document tree.
- Add, modify and remove attributes.
- Modify styles on an element without wiping out unrelated styles.
- Easily add event handlers with cross-browser problems smoothed out for you.
- Handle ajax requests easily.
- Plugins to handle even more things. (I was able to easily drop the date picker into my existing date fields.)