简体   繁体   English

如何在表格行/表格数据中查找文本

[英]How to find the text in a table row/table data

I'm trying to change the color of the text in table row with the class '24hrs'. 我正在尝试使用“ 24hrs”类更改表格行中文本的颜色。 I used jquery to find the text, but i just can't figure it out. 我使用jquery来查找文本,但我只是无法弄清楚。

This is the table i'm working with 这是我正在使用的桌子

            <table class="table" id="characters-table">
            <thead>
                <tr>
                    <th>Logo</th>
                    <th>Abbreviation</th>
                    <th>Coin</th>
                    <th>Price</th>
                    <th>Market Cap</th>
                    <th>24hr</th>
                    <th>More info</th>
                </tr>
            </thead>
            <tbody>
                <template id="all-characters-template">
                    {{#Data}}
                    <tr>
                        <td><img class="img-coin" src="https://www.cryptocompare.com{{CoinInfo.ImageUrl}}"/></td>
                        <td class="character-id">{{CoinInfo.Name}}</td>
                        <td>{{CoinInfo.FullName}}</td>
                        <td>{{DISPLAY.EUR.PRICE}}</td>
                        <td>{{RAW.EUR.MKTCAP}}</td>
                        <td class="24hrs">{{DISPLAY.EUR.CHANGEPCT24HOUR}}</td>
                        <td><button class="btn btn-info character-info-btn" data-toggle="modal" data-target="#myModal">More Info</button></td>
                    </tr>
                    {{/Data}}
                </template>

I tried this, but it coudln't find anything 我试过了,但找不到任何东西

console.log($("#all-characters-template").closest("tr").find(".24hrs").text());

Thanks in advance 提前致谢

As already commented you try to use the id of your template engine, not of your rendered html element. 如前所述,您尝试使用模板引擎的ID,而不是呈现的html元素的ID。 So try this instead: 因此,请尝试以下操作:

$('#characters-table tbody .24hrs').css('color', 'red');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM