Check a checkbox in a table row where a "delete" icon has been clicked on using JQuery -
first, i'd want tell i'm not native speaker please forgive me mistakes. also, first time posting here.
here go.
i've searched days everywhere (especially here) mistakes have made in code. it's stupid mistake can't put finger on it. i'm new javascript , jquery reason.
i have table checkbox , delete icon in first cell of each row of table :
<tr> <td colspan="2"> <span> <input type="checkbox" class="checkbox-select" value="13"/> </span> <a href=""> <img class="delete" src="/img/icons/delete.png" title="delete" alt="delete" align="right"/> </a> </td> ... </tr> what need able check checkbox when clicking on icon (img). i've tried , doesn't work :
$('.delete').click(function(){ var td = $(this).closest('td'); var chkbox = td.children('.checkbox-select'); chkbox.checked = true; // or chkbox.prop('checked', true); }); please provide me solution problem. thanks.
you doing right . need to .find() instead of .children()
$('.delete').click(function(){ var td = $(this).closest('td'); var chkbox = td.find('.checkbox-select'); chkbox.prop('checked',true); }); .children() search immediate descendants. .find() enite inner nodes
Comments
Post a Comment