On Jul 9, 2007, at 23:57 , Erik Beeson wrote:
In fact, if you find yourself doing a lot of if(something exists) {
... } else { ...}, you might want to consider trying to move some of
your code into a plugin. Most jQuery functions/plugins already deal
with the if(exists)... part by simply not executing if nothing is
selected.
Along those lines, I especially like using .each() for this kind of
logic:
$('#myId').each(function() {
// do things with "this" here
});
The .each() functions as an "if," automatically scales to multiple
matches (often without planning for it), and as a bonus creates a
little namespace in the function where you can declare local variables.
--
Jonathan Chaffer
Technology Officer, Structure Interactive