I'm trying to use addClass to give me zebra-striped tables on my Joomla template. Im using the following code:
<script>
jQuery(function($) {
$("tr:odd").addClass("odd");
});
</script>
I've been able to use the tr:odd selector to add css to table rows dynamically, but when i use the addClass function it just doesnt (I checked the source code produced and none of the table rows have the class "odd").
Havn't a clue what I could be doing wrong, would appreciate any help.
The addClass() method adds one or more class names to the selected elements. This method does not remove existing class attributes, it only adds one or more class names to the class attribute. Tip: To add more than one class, separate the class names with spaces.
jQuery hasClass() Method The hasClass() method checks if any of the selected elements have a specified class name. If ANY of the selected elements has the specified class name, this method will return "true".
So you know, changes to the DOM with Javascript are not reflected when you view the source.
That code should work if your CSS looks like this...
tr.odd td
{
background:#070;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With