Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6122535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:54:38+00:00 2026-05-23T15:54:38+00:00

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

  • 0

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 being selected and acted upon looks like this:

<td width="20px"><input type="checkbox" class="chkDeleteItem" name="deleteItem[]" value="' . $rowItem['itemID'] . '" /></td>

I’ve gone over the jQuery documentation, but I still don’t understand the difference. (Is it me or is that documentation sometimes slightly “nebulous” in clarity of content?)

Added Info:

Apparently my attempt a generic examples is confusing people! Along with the (previously) missing parenthesis in the first example. 🙁

The first example comes from a line in my code that removes the <tbody> for any rows with a checkbox that is checked:

$.each($('#classesTable input[name="deleteClasses[]"]:checked').parent().parent().parent().remove());

The second example comes from a situation where I look through the #classesTable for any checked checkboxes and remove its matching item in a dropdown.

$('#classesTable input[name="deleteClasses[]"]:checked').each(function(){
    $('#classesList option[value="' + $(this).attr('value') + '"]').remove();
});

I understand that they do two different things, but not to the point that I’d be able to 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:54:39+00:00Added an answer on May 23, 2026 at 3:54 pm

    Description:

    .each is an iterator that is used to iterate over only jQuery
    objects collection while jQuery.each ($.each) is a general
    function for iterating over JavaScript objects and arrays.


    Examples

    1) Using $.each() function

    var myArray = [10,20,30];
    
    $.each( myArray, function(index, value) {
       console.log('element at index ' + index + ' is ' + value);
    });
    
    //Output
    element at index 0 is 10
    element at index 1 is 20
    element at index 2 is 30
    

    2) Using .each() method

    $('#dv').children().each(function(index, element) {
        console.log('element at index ' + index + 'is ' + (this.tagName));
        console.log('current element as dom object:' + element);
        console.log('current element as jQuery object:' + $(this));
    });
    
    //Output
    element at index 0 is input
    element at index 1 is p
    element at index 2 is span
    

    Resources

    • https://api.jquery.com/jquery.each/
    • http://api.jquery.com/each/
    • jQuery to loop through elements with the same class
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the point using this syntax div.card > div.name What's the difference between this
So I read this great thread: Difference between each instance of servlet and each
What is the difference between this: this.btnOk.Click += new System.EventHandler(this.btnOK_Click); and this? this.btnOk.Click +=
what would be the difference between this class Class1 { public string prop1 {
Is there any essential difference between this code: ThreadStart starter = new ThreadStart(SomeMethod); starter.Invoke();
What is the difference between this two codes? class SomeClass { SomeType val =
I am trying to understand the difference between this: if (isset($_POST['Submit'])) { //do something
I just noticed a new term pimpl idiom, what's the difference between this idiom
What's the difference between these: This one works: char* pEmpty = new char; *pEmpty
Is there a difference between Cursor.Current and this.Cursor (where this is a WinForm) in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.