[Proto-Scripty] Re: Last table row
On Jun 5, 8:15 pm, Jeztah webmas...@thecarmarketplace.com wrote: Morning... Very silly and easy question but my brain isn't working today How can i get the last row of a table (table id=foo) ... Tables have a rows collection that includes all rows in the table. Try: var rows = document.getElementById(tableID).rows; var lastRow = rows[rows.length -1]; Or if you want something much faster in IE: var rows = document.getElementById(tableID).getElementsByTagName ('tr'); var lastRow = rows[rows.length -1]; -- Rob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Last table row
Jeztah wrote: Morning... Very silly and easy question but my brain isn't working today How can i get the last row of a table (table id=foo) ... The row is inserted dynamically via an ajax request so its not on the page at load time!. $('foo').select('tr:last'); Unlike jQuery, Prototype.js uses standard CSS selectors only. Try $$('#footr:last-child'); Why $$('#foo') and not $('foo').select()? If you had some nested tables inside table#foo, then the select clause would return last rows of each of those nested tables along with the last row of foo table. Please also take note, that if you have tbody, thead or tfoot elements in the table then you will get one tr per each of that elements. Even if you have not tbody in your html, current browsers might create one dynamically for you, in the process of html error correction. This, however, should not be a problem since ther would be only one tbody for the table. If you have more than one tbody, then try this: $$('#footbody:last-childtr:last-child'); If you have also a tfoot, then use tfoot in the above. Best regards, SWilk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Last table row
TY muchly Regards Alex - Original Message - From: Szymon Wilkołazki wilkola...@gmail.com To: prototype-scriptaculous@googlegroups.com Sent: Friday, June 05, 2009 11:33 AM Subject: [Proto-Scripty] Re: Last table row Jeztah wrote: Morning... Very silly and easy question but my brain isn't working today How can i get the last row of a table (table id=foo) ... The row is inserted dynamically via an ajax request so its not on the page at load time!. $('foo').select('tr:last'); Unlike jQuery, Prototype.js uses standard CSS selectors only. Try $$('#footr:last-child'); Why $$('#foo') and not $('foo').select()? If you had some nested tables inside table#foo, then the select clause would return last rows of each of those nested tables along with the last row of foo table. Please also take note, that if you have tbody, thead or tfoot elements in the table then you will get one tr per each of that elements. Even if you have not tbody in your html, current browsers might create one dynamically for you, in the process of html error correction. This, however, should not be a problem since ther would be only one tbody for the table. If you have more than one tbody, then try this: $$('#footbody:last-childtr:last-child'); If you have also a tfoot, then use tfoot in the above. Best regards, SWilk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---