ScottyLabs / HackerHelp

TartanHacks 2017 mentor request and dispatch system
1 stars 0 forks source link

OnClick event listener on HTML table rows misbehaving #46

Closed carbon-steel closed 7 years ago

carbon-steel commented 7 years ago

Sung (Roger) Kim: UC Connan: OSX: HTML/Javascript (jQuery):

Description

I'm assigning an onclick evenlistener to each row of my table. However, whenever I click a row, the eventlistener for the last row get triggered instead of the eventlistener of the row I clicked. I know this because I am printing out on the console which element had their eventlistener triggered.

      $(document).ready(function(){

        for(var j = 0; j < tabs.length; j++){

          var id = id_prefix + j;
          var jqElem = $('#' + id);
          var tab = tabs[j];
          jqElem.click(function(){
            console.log(jqElem);
            //chrome.windows.update(tab.windowId, {"focused":true});
            //chrome.tabs.update(tab.id, {"active":true});
            //window.close();
          });

        }

      });

Screenshots

<If possible, include a screenshot>

germy commented 7 years ago

It looks like you are calling by the id of the element, can you verify that the id's are different for each table row?