Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
Jquery+React $.each() not rebinding my callback to the DOM element?

I'm not sure if React is explicitly relevant, other than that it requires me to explicitly bind the function which is calling .each().

But I have a submit() function for a dynamically generated form. I am using .each() to iterate through the various fields to get the data. As I understand, the callback I supply to .each() is supposed to become bound to the DOM element for the current iteration. Instead however, this is referring to the class that the submit() function is bound to. It looks roughly like:

class MyForm extends React.Component {
    constructor(props) {
        super(props);
        this.submit = this.submit.bind(this);
    }

    submit() {
        $('input.my-input').each(() => {
            console.log(this);
        });
    }
}

And my class object is being printed to the devtools console instead of the DOM element, ie.:

> MyClass {props:..., refs:..., state:...}

I'm assuming this is somehow an issue with submit() being bound. How can I otherwise work around this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!