Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

29
Views
Find element directly above clicked item in dom via jQuery

When an element with the class facetwp-color-label is clicked, I am then trying to use jQuery trigger() on the dom element class="facetwp-color" directly above.

enter image description here

Current code:

$(document).on('click', '.facetwp-color-label', function() {
    $(this).closest('.facetwp-color').trigger('click');
});

I tried with prev(), next(), closest(). None are triggering so far. Here is my manual attempt to confirm .trigger() works on the element I am targeting:

$(document).on('click', '.facetwp-color-label', function() {
    $(this).closest('.facetwp-color').trigger('click');

    console.log(this);
});

Result:

<div class="facetwp-color-label">Cream</div>
7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs