Highlight Table Row by Clicking on the Row


/ Published in: JavaScript
Save to your folder(s)

This is a snippet to highlight the clicked row. The code is in Prototype library format. I am yet to port this into JQuery, but please do email me if you already did.


Copy this code and paste it in your HTML
  1. //data_table is the class of the table
  2. document.onload = $$('.data_table tr ').each(function(e){ highlight_row(e); } );
  3.  
  4.  
  5. //css class 'highlight' is the css code that contains the highlighted background color etc.
  6. function highlight_row(e) {
  7.  
  8. e.onclick = function() {
  9. class_list = e.className;
  10. //alert(class_list.search(/highlight/i));
  11. if (class_list.search(/highlight/i) > -1) {
  12. e.removeClassName('highlight');
  13. } else {
  14. e.addClassName('highlight');
  15. }
  16. }
  17. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.