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 7445369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:48:15+00:00 2026-05-29T11:48:15+00:00

I know the standard way of doing it: $(‘div’).each(function(){ // here `this` is bound

  • 0

I know the standard way of doing it:

$('div').each(function(){
      // here `this` is bound to DOM Element
      // use $(this) to access the jQuery wrapper
})'

But this is a little bit cumbersome because we need to use $(this) everywhere and this causes a performance penalty as shown by http://jsperf.com/jquery-each-this.

I am looking for a way to iterate over a jQuery array/selector with this bound to the jQuery wrapper instead of to the DOM element.

  • 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-29T11:48:16+00:00Added an answer on May 29, 2026 at 11:48 am

    You can use an ordinary loop. and use .slice(index, 1) to get the corresponding jQuery object.

    .eq() does the same thing, and maps to .slice(), so .slice(i, 1) is more efficient than .eq(index).

    var $divs = $('div');
    for (var i=0; i <$divs.length; i++) {
        $divs.slice(i);
    }
    

    Notice that the closure is not present. If you want to use closures, create a temporary function:

    function eachMethod(index, $elem) { /* ... */ }
    var $divs = $('div');
    for (var i=0; i <$divs.length; i++) {
        eachMethod(i, $divs.slice(i, 1));
        // Or, if you even want to preserve `this`
        // eachMethod.call($divs[i], i, $divs.slice(i, 1));
    }
    

    Update: A jQuery plugin to achieve your desired “each-syntax”:

    (function($) {
        $.fn._each = function(method) {
            // this points to the jQuery collection
            for (var i=0; i <this.length; i++) {
                method.call(this[i], i, this.slice(i, 1));
            }
            return this;
        };
    })(jQuery);
    // Usage:
    $('div')._each(function(index, $elem) {
        // this points to the DOM element
        // index to the index
        // $elem to the jQuery-wrapped DOM element
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know what is the standard way of doing it. currently I'm
i would like to know what is the standard/best way of doing the following:
I know the standard way of using the null coalescing operator in C# is
Does anyone know a standard way to keep alive the http session as long
I'd like to know the standard way to benchmark a SQL Sever Query, preferably
Does anyone know of any 'standard' way to interface with a telephony system (think
I know what's the standard way to document functions, classes and modules, but how
I'm currently building tests using Capybara/Rails, and want to know the most reliable/standard way
Good afternoon I would just like to know the easiest way for standard Console
Ok , I know the two standard ways to create a new thread and

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.