Was just trying to build a fully functional table or grid by using jQuery. I see there are many tutorials with Zebra Stripe Tables by using jQuery. Here I am trying to make a Simple jQuery Zebra Stripe Table with Row Hover Class and Row Highlight Class or Row Selected Class.
Here is an example of how a blank table can be dressed well with simple CSS and jQuery techniques.
The CSS used for this example is as below:
font-family:Arial, Helvetica, sans-serif;
border: 2px solid #940103;
padding: 8px 6px;
border: 1px solid #FFF;
The simple jQuery script or code snippet:
$("table.tablecolors tr:odd").addClass("odd"); //This is not required - you can avoid this if you have a table background
//$("table.tablecolors tr").removeClass("highlightcolor"); // Remove this line if you dont want to de-highlight the previously highlighted row
If you see the above script, you can avoid either “even” or “odd” class and its jQuery declaration if you place a table background color – but it is required when you want to have a different font or different image background or borders, etc.
In the same way, if you don’t want to highlight the previously selected row once another row is clicked, means like if you want to have only one row selected at a time, then you can uncomment the following line – if not leave it as is.
And I don’t think there is any other simple method to achieve this via jQuery? – if so please share the code.
Check the final example and let me know if you are looking out for any further enhancements to be done to the table and its functionality. I can give you one suggestion which I have in mind – like having a header and footer for the tables by using jQuery?
If you have any suggestions to improve please drop me a message – I will look into it.
BTW – This is my first attempt at jQuery tutorials in my WittySparks site – so please welcome me to the jQuery Tutorials world and encourage me to come up with more jQuery scripting or coding with examples or tips :)