hi have following html:
<input type-checkbox data-testid=@model.testdtos[i].id /> <table> @for(var i=0; < @model.testdtos[i].count; i++) { <tr class="hidden" data-testid=@model.testdtos[i].id>show stuff</tr> } </table>
so i'm wanting make when checkbox matching data-testid value checked table row becomes visible.
i tried:
if ($(this).is(":checked")) { var testid = $(this).data('testid'); $("tr[data-testid=testid").show(); }
the problem ide saying testid never used. i'm unsure how value checkbox data-testid , use find correct row show.
testid
variable, need use string concatenation here
$('tr[data-testid="' + testid + '"]').show()
demo: fiddle
but need might be
$(':checkbox').click(function(){ var fn = this.checked ? 'show' : 'hide'; var testid = $(this).data('testid'); $('tr[data-testid="' + testid + '"]')[fn](); })
demo: fiddle
Comments
Post a Comment