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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:27:04+00:00 2026-06-04T20:27:04+00:00

I am iterating over DOM elements using each but when the elements are made

  • 0

I am iterating over DOM elements using each but when the elements are made available inside the .each loop, they will not accept jQuery bind events.

$('#products .page_item').mouseover(function(){
   console.log('this works, adding the mouseover to every selected element');
});

$('#products .page_item').each(function(index, element){
    element.mouseover(function(){
        console.log("this throws 'not a function'");
    });
});

How do I make each element available within the .each loop so I can bind events to them?

(I am iterating over the elements in this manner so I can conditionally exclude some of the elements from the bind, FWIW.)

  • 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-06-04T20:27:06+00:00Added an answer on June 4, 2026 at 8:27 pm

    You need to wrap element in jQuery object:

    $(element).mouseover(function(){
    

    element (or this) is the DOM element, not the jQuery object.

    Full code fixed:

    $('#products .page_item').each(function(index, element){
        $(element).mouseover(function(){
            console.log("This works!");
        });
    });
    

    From the each docs:

    The .each() method is designed to make DOM looping constructs concise and less error-prone. When called it iterates over the DOM elements that are part of the jQuery object. Each time the callback runs, it is passed the current loop iteration, beginning from 0. More importantly, the callback is fired in the context of the current DOM element, so the keyword this refers to the element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am iterating over input elements using .each() and want to get class of
If I modify a Collection while iterating over it using for-each loop, it gives
I'm iterating over a large number of dom elements in Javascript, and I'd like
I am iterating over some elements and I have found that document.getElementById(id) works, but
If I am iterating over each file using : @echo off FOR %%f IN
I am iterating over an table to pick out the form elements from each
I want avoid iterating over a nil array. My bad solution: if nil!=myArr myArr.each
iterating over an array, am printing some div content for each iteration. Whenever the
I'm iterating over records and want to create the toggle-options for records but I
Context When iterating over a set of Rdata files (each containing a character vector

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.