user2672288
user2672288

Reputation:

Set the CSS of a table row

Thought this would be easy, but i'm having trouble!

I have a table and when I search for a row within that table based on a name I want to highlight the row that it has found. I am trying the following code:

    var elem = $("#table-names tr:contains("+ name +")");
    $(elem).css("background-color", "red");

But it isnt working.

Edit (html below):

    <table id="table-names" class="table table-bordered table-hover table-condensed">
        <thead>
            <tr>
                <th align="center">Pos</th>
                <th align="center">Name</th>
                <th align="center">Points</th>
            </tr>
        </thead>
        <tbody> 
            <?php 
                $rows = getPoints(); 
                foreach ($rows->body as $row):
            ?>
                    <tr>
                        <td><?= $row->position; ?></td>
                        <td><?= $row->teamshort; ?></td>
                        <td><?= $row->points; ?></td>
                    </tr>
                <? endforeach ?>
        </tbody>
    </table>

Am I missing something?

Cheers

Upvotes: 0

Views: 63

Answers (1)

codingrose
codingrose

Reputation: 15699

Text inside the parentheses of :contains() needs to be surrounded by quotation marks.

It should be

var elem = $("#table-names tr:contains('"+ name +"')");

More information here.

Upvotes: 2

Related Questions