Let’s say you got some tabular data with input button/anchor tags that ideally will cause previously hidden data to appear.
Attempt 1 went like:
//Simulated row
Click me to show stuff!
I hate messy code, but unfortunately this is PHP so there’s only so much one borderline pyschotic developer can accomplish. Or is there?
//prior to my table
$('a.actionable').live('click',function(){
$($(this).attr('href')).slideToggle();
return false;
});
//Now
Click me to show stuff!
It’s almost elegant if you ignore the PHP inject. JQuery’s .live handler automatically routes all unhandled click events to the closest “.actionable” classed element, then inside the live event handler, you grab the anchor’s href value to get the element Id of what you want to edit.