получить непрямого родителя
есть такое :
<div class="prnt"> <!-- много вложенных тегов --> <button class="btn">Кнопко</button> </div> <div class="prnt"> <!-- много вложенных тегов --> <button class="btn">Кнопко</button> </div> <div class="prnt"> <!-- много вложенных тегов --> <button class="btn">Кнопко</button> </div> . . . Нужно получить непрямого конкретного родителя <div class="prnt"> для конкретной кнопки (при нажатии) |
<!DOCTYPE HTML> <html> <head> </head> <body> <div class="prnt"> <div> <div> <div> <div> <div> <button id="bt_test" class="btn">Кнопко</button> </div> </div> </div> </div> </div> </div> <script> var bt = document.getElementById("bt_test"); var parent = bt.parentNode; while(parent && parent.className != "prnt") parent = parent.parentNode; console.log(parent); </script> </body> </html> |
|
Часовой пояс GMT +3, время: 01:25. |