javascript - Find and remove style attribute on click -
i trying remove style attribute singular tr tag in table when corresponding tag clicked. have been trying code cannot find solution.
here fiddle: http://jsfiddle.net/q2nb08t6/12/ jquery:
$(".tr_table").click(function(){ $(".tg_table").removeattr('style'); //$(".tg_table").parent().find("tg_table").removeattr('style'); //$(".tg_table").parent().removeattr('style'); //$(".tg_table").each().removeattr('style'); });
- change approach. apply style on
tr
level instead oftable
level - use removeclass() remove class when clicked. or, can use toggleclass() toggle class when clicked.
$(".tr_table").click(function() { $(this).toggleclass('tr_table'); });
.tg_table { width: 100% } .tr_table { cursor: pointer; } tr.tr_table { background-color: rgba(255, 0, 0, 0.5) !important; color: white !important; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <table class="tg_table" border="1" style=""> <tr class="tr_table"> <td>jill</td> <td>smith</td> <td>50</td> </tr> <tr class="tr_table"> <td>eve</td> <td>jackson</td> <td>94</td> </tr> <tr class="tr_table"> <td>neil</td> <td>mark</td> <td>30</td> </tr> <tr class="tr_table"> <td>mike</td> <td>ford</td> <td>98</td> </tr> </table>
update
unfortunately cannot change approach table generated php script
in case, can change tr
styles css()
$(".tr_table").click(function() { $(this).css('background', 'white'); $(this).css('color', 'black'); });
.tg_table { width: 100% } .tr_table { cursor: pointer; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <table class="tg_table" border="1" style="background-color: rgba(255,0,0,0.5) !important;color:white !important;"> <tr class="tr_table"> <td>jill</td> <td>smith</td> <td>50</td> </tr> <tr class="tr_table"> <td>eve</td> <td>jackson</td> <td>94</td> </tr> <tr class="tr_table"> <td>neil</td> <td>mark</td> <td>30</td> </tr> <tr class="tr_table"> <td>mike</td> <td>ford</td> <td>98</td> </tr> </table>
Comments
Post a Comment