html dom获得父div,获取元素的父div
生活随笔
收集整理的這篇文章主要介紹了
html dom获得父div,获取元素的父div
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
如果您正在尋找一種比直接父元素更遠的元素,可以使用一個在DOM上查找直到找到一個或沒有找到的函數:
// Find first ancestor of el with tagName
// or undefined if not found
function upTo(el, tagName) {
tagName = tagName.toLowerCase();
while (el && el.parentNode) {
el = el.parentNode;
if (el.tagName && el.tagName.toLowerCase() == tagName) {
return el;
}
}
// Many DOM methods return null if they don't
// find the element they are searching for
// It would be OK to omit the following and just
// return undefined
return null;
}
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的html dom获得父div,获取元素的父div的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html页面选择指定条件在下方显示,如何
- 下一篇: 2021江苏地区高考成绩排名查询,202