Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Add css class to a table

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #239791
    jerryr125
    Participant

    Hi – 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 Parking

    I am thinking something that searches for the word (say Garage Spaces) and then adds the div=”garagespaces” to the tr tag (row).

    thoughts ?

    • jerry
    #239794
    Paulie_D
    Moderator

    $('table:contains("Garage")') .addClass('garage');

    http://codepen.io/Paulie-D/pen/vGZKEj

    #239795
    Paulie_D
    Moderator

    Adding a class to the row may not be what you are looking for…depends on what you are trying to do:

    http://codepen.io/Paulie-D/pen/VaWjaX

    #239796
    jerryr125
    Participant

    this works perfect – now the question – I need to have this run when a wordpress blog post loads – how do I do that ??

    • jerry
    #239797
    jerryr125
    Participant

    Paulie_D – this is excellent !
    Thank you !
    How I run this on blog post in wordpress ?

    #239798
    Paulie_D
    Moderator

    That’s an entirely different question…I’d ask that in the PHP area.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.