Home >Web Front-end >JS Tutorial >How to modify the tr class in jquery
Methods to modify classes: 1. Use removeClass() to remove the specified class from the tr element, the syntax is "$("tr").removeClass(class)"; 2. Use addClass() to the tr element To add a specified class, the syntax is "$("tr").addClass(class)".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
jquery method of modifying the tr class
First use removeClass() to remove the specified class from the tr element
Then use addClass() to add the specified class to the tr element
Example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("button").click(function() { $("tr").removeClass("intro1"); $("tr").addClass("intro2"); }); }); </script> <style type="text/css"> .intro1 { color:red; } .intro2 { color:blue; } </style> </head> <body> <table border="1"> <caption>人物信息</caption> <tr class="intro1"> <th>姓名</th> <th>年龄</th> </tr> <tr class="intro1"> <td>Peter</td> <td>20</td> </tr> <tr class="intro1"> <td>Lois</td> <td>20</td> </tr> </table><br /> <button>修改tr的类</button> </body> </html>
Recommended related video tutorials : jQuery Tutorial(Video)
The above is the detailed content of How to modify the tr class in jquery. For more information, please follow other related articles on the PHP Chinese website!