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

191
Views
I want to access first $(this) from the second level in jquery

i want to get the data attribute on the second level

$('.filter-select').each(function() {
        console.log($(this).data()) // this gives me all data 
        $(this).on('change', function() {
            console.log($(this).data()) // but here gives me only on that i clicked i want it all
        })

    })
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can simply:

$('.filter-select').each(function() {
        const allData = $(this).data();
        $(this).on('change', function() {
            // use allData to access all
        })

    })
about 4 years ago · Juan Pablo Isaza Report

0

Instead of using each, and then trying to attach event listeners to each .filter-select element use event delegation to attach a listener to a parent element so that it captures the change events from all the .filter-select elements as they "bubble up" the DOM.

$(document).on('change', '.filter-selector', handleChange);

function handleChange() {
  console.log($(this).data());
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select data-id="1" class="filter-selector">
  <option selected>Choose (id: 1)</option>
  <option value="1">1</option>
  <option value="2">2</option>
</select>
<select data-id="2" class="filter-selector">
  <option selected>Choose (id: 2)</option>
  <option value="1">1</option>
  <option value="2">2</option>
</select>

about 4 years ago · Juan Pablo Isaza Report
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!