html - Check whether a class exists in any row of a table in JavaScript -
i have table (simplified question):
<table><br> <tr onclick="selectrow"><br> <td>table data</td><br> <td>table data</td><br> <td>table data</td><br> </tr><br> <tr class="selected" onclick="selectrow"><br> <td>table data</td><br> <td>table data</td><br> <td>table data</td><br> </tr><br> </table>
class="selected"
result of clicking on row. want make button when clicked, return true if there row class 'selected', , false if there not.
any appreciated. thanks.
function checkexist(){ var mytr = document.getelementsbytagname('tr'); for(var i=mytr.length; i--;){ if(mytr[i].classname.match('(^|\\s+)selected(\\s+|$)')){ alert('true');//return true; return; } } alert('false'); //return false }
and attach button or link this:
<table> <tr onclick="selectrow"> <td>table data</td> <td>table data</td> <td>table data</td> </tr> <tr class='selected' onclick="selectrow"> <td>table data</td> <td>table data</td> <td>table data</td> </tr> </table> <a href='#' onclick='checkexist()'>click me find out</a>
Comments
Post a Comment