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

243
Views
On Multiple click events within Div return as one click

I am in a bit of a bind. I have multiple cards.. with several click events possible (7) to be exact inside of each card.

I've added the same class to them all (each click event) with data tags that return different values.

Basically, I want to track all click events (7) at different times and check them as one per card.

If the user does anything within the card at all, count it as one event.. I am basically trying to count the views per card.

Right now I have something like this

 $(document).on("click", ".test", function() {
    console.log('Testing Stats View capture');
    var that = $(this);
    var testStats = that.data('capture-stats');
    console.log(testStats);   
 }));
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

count views per card

You can store the count on each card using this.data():

 $(document).on("click", ".card", function() {
 
     var clickcount = $(this).data("clickcount") || 0;
     clickcount++;
     $(this).data("clickcount", clickcount);
     
     console.log($(this).text() + " clicked: " + clickcount); 
     
 });
.card { cursor: pointer; user-select: none;  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='card'>card 1</div>
<div class='card'>card 2</div>
<div class='card'>card 3</div>

about 4 years ago · Juan Pablo Isaza Report

0

You could add a data attribute to the element triggering the event, at the end of your handler, and check its presence at the beginning, as a condition to perform a given logic:

 $(document).on("click", ".test", function() {
    console.log('Testing Stats View capture');
    var that = $(this);
 
    //if the prop data-event-triggered is not set yet for this element
    if ( !that.data('event-triggered') ){
      var testStats = that.data('capture-stats');
      //adds the prop data-event-triggered for this element
      that.data('event-triggered','true');
      console.log('event triggered-${testStats}');   
    }    
 });
.test {
  width: 100px;
  height: 100px;
  background: gray;
  cursor: pointer;
  margin-bottom:10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="test" data-capture-stats="1">1</div>

<div class="test" data-capture-stats="2">2</div>

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!