[jQuery] Newbie code review please?
Having just made my first real piece of jQuery code, I'm already
wondering if it can be made more concise :-)
It's an unobtrusive mod to an existing page (in Best Practical's RT
ticketing system). The page has a table of ticket entries, where of the
TDs in each row is a checkbox. I want to be able to click anywhere on
the row to toggle the checkbox.
This is my currently working version. Can I attach an event to the
parent's parent, but have the matching checkbox's ID passed to it, in
one chain?
$('input:checkbox[@name^=UpdateTicket]').each(
function() {
var myid = $(this).attr('name');
$(this).parent().parent().click( function(event) {
if(event.originalTarget.tagName != 'INPUT')
{
var cb = $('input:checkbox[@name='+myid+']');
cb.attr('checked', !cb.attr('checked'));
return false;
}
});
});
Thanks for any pointers - I'm enjoying adding functionality to RT this
morning. The ContextMenu plugin has also made an appearance in another spot.
Cheers,
Howie