Hei guys. I want my Checkbox to be "checked" after i click the last td field of a row. I tried it with JQuery but unfortunately i always checked all checkboxes. I just want to check the td at the row i clicked.
Thats how i build my table.
<table class="table table-striped" id="notfallTable">
<tr>
<th value="name">Name</th>
<th>Nachname</th>
<th>Nummer</th>
<th>Abteilung</th>
<th id="thCheckbox"><button id="checkAll" class="btn btn-success">Check all</button>
</th>
</tr>
</table>
$.getJSON("NotfallSMS.json", function(data){
var items=[];
var checkbox="test";
$.each(data, function(key, val){
items.push("<tr>");
items.push("<td contenteditable>"+val.Name+"</td>");
items.push("<td contenteditable>"+val.Nachname+"</td>");
items.push("<td contenteditable>"+val.Nummer+"</td>");
items.push("<td contenteditable>"+val.Abteilung+"</td>")
items.push("<td class='check'><input class='check' type='checkbox'>"+""+"</input></td>");
items.push("</tr>");
});
$("<tbody/>", {html: items.join("")}).appendTo("table");
});
I hope you can help me out. Greetings Elfdow
To achieve this you can hook a click event handler to the
td.checkelements which usesfind()to retrieve the checkbox within the cell and toggles itscheckedproperty, like this:However it's worth noting that you can achieve the exact same behaviour without JS or jQuery by using CSS instead. Wrap the checkbox in a
labeland use CSS to set it todisplay: block: