What you want to do is prevent this from occurring by calling Event.stopPropagation() in the handlers for your clicks. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. Using alerts, I see the function being assigned for each iteration. I presume you know clearly how many rows does your table have. What distinguishes top researchers from mediocre ones? $("#table tr").click(function(){ javascript add on click event on table rows | Codexpedia Connect and share knowledge within a single location that is structured and easy to search. function example4 () { var table = document.getElementById ("tableid4"); var rows = table.rows; // or table.getElementsByTagName ("tr"); for (var i = 0; i To subscribe to this RSS feed, copy and paste this URL into your RSS reader. What norms can be "universally" defined on any real vector space with a fixed basis? Asking for help, clarification, or responding to other answers. Connect and share knowledge within a single location that is structured and easy to search. You can then use the buttons to fire up actions on the selected row. You will need to use querySelectorAll() to select all table cells. var table = document.getElementById("tableID"); if (table != null) { for (var i = 0; i < table.rows.length; i++) { table.rows[i].onclick = function() { tableText(this); }; } } function In the addNewRow function, I'm going to check the current visible rows count and show the next row if there are any row invisible. If you use a button to select a row, then how would you de-select it? This would be so much work on the developer and on the disk. Why not say ? You can access the first element adding the following code to the highlight function $(this).find(".selected td:first").html() Working Code: JSFI Making statements based on opinion; back them up with references or personal experience. 601), Moderation strike: Results of negotiations, Our Design Vision for Stack Overflow and the Stack Exchange network, Temporary policy: Generative AI (e.g., ChatGPT) is banned, Call for volunteer reviewers for an updated search experience: OverflowAI Search, Discussions experiment launching on NLP Collective. You just have to remove an extra function and script will be like this. I have listed the max table rows in the HTML. How to cut team building from retrospective meetings? To subscribe to this RSS feed, copy and paste this URL into your RSS reader. Simple example using pure javascript HTML: You will then have to iterate through the nodelist and attach the click Add a single listener to the tbody of the table, and retrieve the clicked cell from the event object, like this: This technique is called event delegation, it takes the advantage of the event bubbling mechanism, where the events are fired on every ancestor element of the actual clicked element too. It returns nothing. AND "I am just so excited.". Why not say ? By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. What if the president of the US is convicted at state level? Disclaimer: Only tested in Chrome and code can almost certainly be optimised. Securing Cabinet to wall: better to use two anchors to drywall or one screw into stud? When clicking on second, third - returns nothing. $(this).ad Use the Array.forEach () method to iterate over them. I thought the way I nested a return f() inside a function makes the inner function close over the scope of the outer function's variables, thus giving me access to the row information.