Friday, June 12, 2009

What ASP.NET Developers Should Know About jQuery


Use selectors. Think in sets.
In the ASP.NET world, it’s rare to select sets of controls through queries. Instead, we’re accustomed to referencing a single control by its unique ID. Of course this is possible in jQuery too, but its selector engine is far more sophisticated.

Using selectors to identify a set of one or more elements is cleaner and more expressive than the iterative machinations you may be used to in ASP.NET server-side code. Before parsing out an ID or iterating over a group of elements in search of certain ones, be sure that the task isn’t more easily accomplished through a jQuery selector.

Use CSS classes for more than just styling.
Another technique that is counterintuitive at first is the use of CSS classes as flags. Coupled with jQuery’s selector engine, “flag” classes are surprisingly powerful.