在沒有jQuery的情況下查找最近的元素 - Finding closest element without jQuery

問題:

I am trying to find the closest element with a specific tag name without jquery.我試圖在沒有 jquery 的情況下找到具有特定標籤名稱的最近元素。 When I click on a <th> I want to get access to the <tbody> for that table.當我單擊<th>我想訪問該表的<tbody> Suggestions?建議? I read about offset but didn't really understand it too much.我讀過偏移量,但並沒有真正理解它。 Should I just use:我應該只使用:

Assume th is already set to clicked th element假設 th 已經設置爲 clicked th 元素

th.offsetParent.getElementsByTagName('tbody')[0]

解決方案:

參考: https://stackoom.com/en/question/1GJLJ
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章