Reputation: 447
On my page, I use bootstrap. I created table and it has 3 classes, check it:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<table class="table table-striped table-bordered">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
Now I use code jQuery. This code added class highlight. Class highlight:
.highlight {
background-color: orange;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<table class="table table-striped table-bordered">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
When table has only one class: "table" it's working. But I must have table-striped and table-bordered. When it is, highlight is working only with even numbers. How can I fix that?
Upvotes: 0
Views: 47
Reputation: 32275
In your jQuery code, instead of
.highlight
use .highlight > tbody > tr
.highlight > tbody > tr {
background-color: orange;
}
Upvotes: 1
Reputation: 1818
If I understand your problem: every time you add highlight
with jQuery to your table
nothing happens (or not all table raws become orange).
Probably if the background-color
of the table isn't set on table
but on td
.
Try to change simply your CSS
selector:
.highlight{
background-color:orange;
}
to
.highlight tr td{
background-color:orange;
}
Watch this example: http://jsfiddle.net/pujsghe6/
Upvotes: 1
Reputation: 2629
It's a css specificity issue.
Bootstrap applies the alternating row class like this:
.table-striped>tbody>tr:nth-of-type(odd)
You need to be as specific as that or more.
Row highlight example:
.table>tbody>tr.highlight>td {
// change your background color here
}
Cell highlight example:
.table>tbody>tr>td.highlight {
// change your background color here
}
Note: I'm assuming you want to highlight some rows or cells, not the entire table.
Upvotes: 2