Mar 292010
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 <td> <a href="#" onclick="$('#my_SubData<?= $currentRecordId ?>').slideToggle(); return false">Click me to show stuff!</a><br> <div id="my_SubData<?= $currentRecordId; ?>" style="display: none "> Blah blah blah....</div> </td>
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 <td> <a href="#my_SubData<?= $currentRecordId ?>')" class="actionable">Click me to show stuff!</a><br> <div id="my_SubData<?= $currentRecordId; ?>" style="display: none "> Blah blah blah....</div> </td>
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.
Sorry, the comment form is closed at this time.