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.
here are two ways/methods to create zebra-striped, one way using jQuery and one way using CSS3.
First method– using jQuery
HTML
To create the "striped" table, we need to create a table with an id to identify it and apply the style only to that table, in this example we'll name it "zebra_triped"
CSS
We create a style for the even rows and another for the odd rows.
jQuery
Finally, we need to create the jQuery code that will add the CSS classes to the tr tags, this is achieved with this code:
The first line selects the odd tr tags inside an element with the id zebra_triped and adds them the class "oddRow", the last line does the same with the even lines, adding them the class "evenRow".
Second method– using CSS
** My favorite :)*
HTML
CSS
-moz-border-radius: 11px; and -webkit-border-radius: 11px; Here I’m defining the radius/round corner for the container’s border for each corner. This is only one line specify the radius property for all corners, but I can target specific corner as below:
and
Hope this helps,
Ahmed
jQuery does not change source code of HTML document, it changes DOM structure (in-memory representation of document). To see these changes you have to use browser plug-in that shows DOM of document (Firebug for Firefox, Developers Tools (F12) for IE).
Try adding the class to the
td
instead like this: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...