简体   繁体   中英

Limit scope of jQuery

var tr0HTML = $('<tr id="exp_line1"></tr>').appendTo(tbody);

What could the best possible way to use .css or any other jQuery to style this element based on the condition?

All I could see is that the change has been implemented to whole page not for the particular scenario!

Update: I want to style borders to the table which has 3 different types of rows. Rows are being displayed if the data is provided.

If I have understood your question... Something as simple as this should work:

 tr.type-1 td{ border: 2px solid hotpink; } tr.type-2 td{ border: 2px solid purple; } tr.type-3 td{ border: 2px solid black; }
 <table> <tbody> <tr class="type-1"> <td>Type 1</td> </tr> <tr class="type-2"> <td>Type 2</td> </tr> <tr class="type-3"> <td>Type 3</td> </tr> </tbody> </table>

Your jQuery code would look like this: $('<tr id="exp_line1" class='type-1'></tr>').appendTo(tbody)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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