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

131
Views
Adding .not() on event handling to dynamically added content

With event handling on dynamically added content, I use:

$('#static-div').on('click', '.dynamic-content', function () {
    // do something
});

What should I do if I want to add a .not() to this code? As in, I want to click anything with ".dynamic-content" but not apply the event handling to ".should-not-be-clicked"

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

0

Add :not() to the selector

$('#static-div').on('click', '.dynamic-content:not(.no)', function () {
    console.log('clicked')
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="static-div">
  <button type="button" class="dynamic-content">Y</button>
  <button type="button" class="dynamic-content no">N</button>
  <button type="button" class="dynamic-content">Y</button>
  <button type="button" class="dynamic-content no">N</button>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

There is a not css selector which you can add to this.

Check it out here

$('#static-div').on('click', '.dynamic-content:not(.should-not-be-clicked) ', function () {
    // do something
});
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!