You are viewing limited content. For full access, please sign in.

Discussion

Discussion

jQuery each row showing twice - when to take a break

posted on May 30, 2018 Show version history

Can someone please help me to understand why this .each function shows 2 results for each row? I am guessing it a selector syntax issue, but I can't figure it out. Thank you in advance!

    $("#q397 tbody").find("tr").each(function() { 
    var delArray = [];
    var delTd = $(this).find('td.delPrevAtt'); 
    delArray.push(1);

@████████, I know you are in tomorrow already :)

Thanks!

0 0
replied on May 30, 2018

Hi Chris,

Are you saying that even when you only have one row in your table, your delArray ends up as [1,1]? Or are you saying that you get two hits for 'td.delPrevAtt' in each row?

I think answering these questions and posting a screenshot of the DOM of your table from console (with tbody and one of tr nodes expanded) would help Rui get a better idea. 

Best,

Ken

1 0
replied on May 31, 2018 Show version history

Ken, thanks for the second set of eyes.

Of course, I omitted something important. This code is nested inside an on click which in turn was looking for a class which appeared twice.

I changed the selector and simplified the code. I used this to get the total # of checked checkboxes in the table:

$("#q397 table").find('input[type=checkbox]:checked').length

 

Anyone have tips for when you just need to walk away and come back with a fresh set of eyes? I seem to keep trying when I really need to quit for an hour or so.

0 0
replied on May 31, 2018

Are you sure it isn't the onClick getting triggered more than once?  Sometimes I've noticed events triggering more than expected.

0 0
replied on May 31, 2018

I tested that out by changing it to mouseup and mousedown. No, it was because I was triggering it incorrectly on something like this:

  $('#q397').on("click", '.delCell', function(){

And the .delCell class appeared twice in each row. My bad!! I am up and running now. 

Thanks for the hand :)

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.