ajax toggle magic

Here’s an obvious-in-retrospect bit of code:


$.fn.liveAndRun = function(event_name, f) {
$(this).live(event_name, f);
f.apply(this);
}

It’s for when you have checkboxes or radio buttons that toggle the visibility of form inputs. If validation fails and you send the form back to the browser, using $(selector).liveAndRun instead of $(selector).live means that the functions that sort out visibility happen on page load, not just when the checkbox gets clicked. And happy unicorns ride ponies to a delicious breakfast.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s