Hello, tell me, please, my tables are in a div. I need to click on the table in the alert to display in what id it is.
$("table").click(function(){alert(...)}) Thank you in advance.
Hello, tell me, please, my tables are in a div. I need to click on the table in the alert to display in what id it is.
$("table").click(function(){alert(...)}) Thank you in advance.
If the tables are nested directly in divs, then
$("table").click(function () { alert($(this).parent().attr('id')); }); $("table").click(function() { // Так мы ищем первый родительский div, у которого есть атрибут ID var parentDivId = $(this).closest('div[id]').attr('id'); alert(parentDivId) }); table, table td { border: 1px solid #ccc; } div + div { margin-top: 10px; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div id="first"> <div> <table> <tr> <td>Я столбец 1 в таблице 1</td> <td>Я столбец 2 в таблице 1</td> </tr> </table> </div> </div> <div id="second"> <table> <tr> <td>Я столбец 1 в таблице 2</td> <td>Я столбец 2 в таблице 2</td> </tr> </table> </div> Source: https://ru.stackoverflow.com/questions/420226/
All Articles