What is the difference between this:
$.each($('#myTable input[name="deleteItem[]"]:checked').do_something());
and this:
$('#myTable input[name="deleteItem[]"]:checked').each(function() { do_something });
The html for the table cell that is selected and valid is as follows:
<td width="20px"><input type="checkbox" class="chkDeleteItem" name="deleteItem[]" value="' . $rowItem['itemID'] . '" /></td>
I looked through the jQuery documentation, but I still don't understand the difference. (Is it me or is this documentation sometimes a little βhazyβ in the clarity of the content?)
Information added:
Apparently, my attempt at typical examples confuses people! Along with the (previously) missing brackets in the first example .: (
The first example comes from a line in my code that removes <tbody> for any lines with a checkmark selected:
$.each($('#classesTable input[name="deleteClasses[]"]:checked').parent().parent().parent().remove());
The second example comes from the situation when I look at #classesTable for all checked checkboxes and delete the corresponding item in the drop-down list.
$('#classesTable input[name="deleteClasses[]"]:checked').each(function(){ $('#classesList option[value="' + $(this).attr('value') + '"]').remove(); });
I understand that they do two different things, but not so much that I can say: "I need to use $ .each () in this case and .each (function () {}) in another case.
Are they interchangeable at all? Only in some cases? Never?
jquery each
marky Jul 07 2018-11-17T00: 00Z
source share