Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to add click event to table row js

function addRowHandlers() {
  var table = document.getElementById("tableId");
  var rows = table.getElementsByTagName("tr");
  for (i = 0; i < rows.length; i++) {
    var currentRow = table.rows[i];
    var createClickHandler = function(row) {
      return function() {
        var cell = row.getElementsByTagName("td")[0];
        var id = cell.innerHTML;
        alert("id:" + id);
      };
    };
    currentRow.onclick = createClickHandler(currentRow);
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript getter arrow function 
Javascript :: javascript form data 
Javascript :: build react app 
Javascript :: print stuff in console javascript 
Javascript :: decode jwt token nodejs 
Javascript :: how to install react fullpage using npm 
Javascript :: Return an html element with react 
Javascript :: eslint disable line 
Javascript :: props in classes 
Javascript :: jquery is not defined error in wordpress 
Javascript :: add marker on map geocoder result mapbox 
Javascript :: convert positive to negative number javascript 
Javascript :: what is dotenv in nodejs 
Javascript :: parallax using npm parallax 
Javascript :: javascript addeventlistener click only works once 
Javascript :: create variable javascript 
Javascript :: sequelize date format 
Javascript :: jquery repeat event on click 
Javascript :: js get folder of current script 
Javascript :: queryselector for jquery 
Javascript :: code to convert rgb to hsl color 
Javascript :: how to disable button if errors object isnt empty in react hook form 
Javascript :: javascript eventlistener 
Javascript :: google script new date 
Javascript :: javascript string compare 
Javascript :: window.addeventlistener multiple events 
Javascript :: capitalize text js 
Javascript :: barcode scanner react js 
Javascript :: how to get bearer token in react 
Javascript :: react redux form validation 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =