I have a row in an html table that contains only images. (this will also be the first line). These images are also connected to the event with a click. When I try to handle the click event, I can find out its parent element (i.e. <td> ). But I want to know its relative serial number in the table row ( <tr >).
<td>
<tr
You can find the serial number with the index() function:
index()
$('td img').click(function() { var ordinal = $(this).closest('tr').children().index($(this).parent()); // ... });
The number of elements before the current element will be its index in the DOM relative to the parent. You can use .prevAll() and get the length of the result set:
.prevAll()
$('td').click(function(){ alert($(this).prevAll().length); });
Demo available on jsfiddle
Source: https://habr.com/ru/post/1312312/More articles:A portable way to count milliseconds in C ++? - c ++https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1312308/cursor-postion-comes-to-start-of-the-edittext&usg=ALkJrhgmTZVi2kvnTmD7Zik4xSWnVMoUkgExcel C # convert cell to percentage - c #Error executing stored procedure using open xml in sql server - sqlRewrite trailing slash - apache2 (or more) ComboBoxes depending on each other - data-bindingElmah sends error message on development server, but not on production - smtpPHP generic form generator / builder - phpHow can I manage a FIFO queue in a database with SQL? - sqlTabItems from the View collection - wpfAll Articles