I have a table within a checkbox and what I want is, when the checkbox is checked and i press the delete button the table must hide. So I tried this:
$('deleteButton').click(function()
{
$('input:checkbox:checked').parents($('table').hide());
});
But it didnt work, I hope someone can help me out with this one?
Thanks in advance!
There are a couple of problems with your code. Firstly, your
deleteButtonselector would match an element named<deleteButton>, which is obviously not valid. I’m guessing you meant it to be anidselector (#deleteButton) or a class selector (.deleteButton).Secondly, this line will hide all of the
tableelements on your page:The reason for that is you call
$('table').hide(), which will hide all of thetableelements, and pass the result of that into theparentsmethod (but do nothing with the result of theparentsmethod). I think what you probably meant was to usetableas a selector to theparentsmethod:However, if the
tableyou want to hide is a descendant of anothertablefurther up the DOM, you probably want to useparentsUntil, or you’ll end up hiding the ancestortabletoo.