Home › Forums › JavaScript › Add css class to a table
- This topic is empty.
-
AuthorPosts
-
March 25, 2016 at 12:47 pm #239791
jerryr125
ParticipantHi – I am working on a wordpress site.
A plugin renders the following table (with no divs or ids defined) :<table style="width: 100%;"> <tr> <th style="width: 25%; text-align: left;">Last Updated</th> <td style="width: 25%;"> 3/2/2016 </td> <th style="width: 25%; text-align: left;">Tract</th> <td style="width: 25%;"> GREYSTONE </td> </tr> <tr class="dsidx-secondary-row"> <th style="text-align: left;">Year Built</th> <td> 1997 </td> <th style="text-align: left;">Community</th> <td> N Shelby/Hoover </td> </tr> <tr> <th style="text-align: left;">Garage Spaces</th> <td> 4.0 </td> <th style="text-align: left;">County</th> <td> Shelby </td> </tr> <tr class="dsidx-secondary-row"> <th style="text-align: left;">Total Parking</th> <td> 4 </td> </tr> </table>
I want to use javascript/jquery to add a css DIV ID to the
tr tags.
the words in the th are constant :
Last Updated
Tract
Year Built
Community
Garage Spaces
County
Total ParkingI am thinking something that searches for the word (say Garage Spaces) and then adds the div=”garagespaces” to the tr tag (row).
thoughts ?
- jerry
March 25, 2016 at 1:22 pm #239794Paulie_D
Member
$('table:contains("Garage")') .addClass('garage');March 25, 2016 at 1:24 pm #239795Paulie_D
MemberAdding a class to the row may not be what you are looking for…depends on what you are trying to do:
March 25, 2016 at 1:32 pm #239796jerryr125
Participantthis works perfect – now the question – I need to have this run when a wordpress blog post loads – how do I do that ??
- jerry
March 25, 2016 at 1:39 pm #239797jerryr125
ParticipantPaulie_D – this is excellent !
Thank you !
How I run this on blog post in wordpress ?March 25, 2016 at 1:45 pm #239798Paulie_D
MemberThat’s an entirely different question…I’d ask that in the PHP area.
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.