We’ve found jQuery to be extremely helpful in widget development, since it really lends itself to efficient code that produces pretty robust results. For example, the accordion default widget template uses jQuery to select elements and move them around smoothly, all with only a few lines of code.
jQuery (http://jquery.com) is a JavaScript library that makes extensive use of selectors and their attributes. A lot of times you can simply use CSS selectors for particular elements in order to manipulate them (like referencing a <div> by its ID). That's where attributes come in: you can add and remove attributes to HTML elements, and modify their properties. jQuery lets you string together properties and so oftentimes only one line of code is needed to perform a number of functions.
If you're new to jQuery, give this article a read:
http://blemble.com/2009/01/comprehensive-introduction-to-jquery/
If you've had some experience in jQuery and want to improve your code, check out this article:
http://marcgrabanski.com/article/5-tips-for-better-jquery-code
For a really comprehensive list of selectors that even has a sandbox to play around in, see this one:
http://codylindley.com/jqueryselectors/
And finally, if you want to get really fancy in how you arrange and manipulate your HTML elements, have a look at Visual jQuery: