I get a Table with Data from a MySql Database via Ajax when i click a Button. It is displayed into a Div. I get the whole HTML with content from my .php script on the Server.
...
$statement->execute();
echo " <table id='tableID' onClick='idfromclick(event)' class='table table-bordered table-hover'>
<thead>
<tr>
<th>Name</th>
<th>Datum</th>
<th>ID</th>
<th>Position</th>
<th>Notiz</th>
</tr>
</thead>
<tbody> ";
foreach ($statement -> fetchAll() as $result)
{
echo "<tr>";
echo "<td align=center>$result[0]</td>";
echo "<td align=center>$result[1]</td>";
echo "<td align=center>$result[2]</td>";
echo "<td align=center>$result[3]</td>";
echo "<td align=center>$result[4]</td>";
echo "</tr>";
}
echo "</tbody>
</table>";
...
When I click on a Row I only need the ID which I get with
function idfromclick(e){
localStorage.setItem("ClickID",e.target.parentNode.cells[2].innerHTML);
}
Now i want that the selected (clicked) Row is in a different Color until another Row is clicked.
This one works with a local Table
<table id="blub" class="table table-bordered table-hover">
<tbody>
<tr><td>Something..blah blah</td><td>Something...blah blah</td><td>Something...blah blah</td></tr>
<tr><td>Something ...blah blah</td></tr>
<tr><td>Something ...blah blah</td></tr>
<tr><td>Something ..blah blah</td></tr>
</tbody>
</table>
<script> $('table tr').each(function(a,b){
$(b).click(function(){
$('table tr').css('background','#ffffff');
$(this).css('background','#c5e9b8');
});
});
</script>
BUT it dont work on my other (php) Table. It seems like no jQuery works?
Why is that so and can i make jQuery works?
The Solutions with only JS are much longer and complicated.
The Solutions with only JS are much longer and complicated.this is why we have JQuery