1,js獲取節點:
父: parentNode 獲取已知節點的父節點。
子: childNodes; 得到全部子節點
children 得到全部子節點
firstChild 獲得第一個子節點
lastChild 獲得最后一個子節點
兄弟:previousSibling 獲取已知節點的前一個節點
nextSibling 獲取已知節點下一個節點
2,jq獲取節點:
父: $('#').parent() 獲取上一級的父節點。
$('#items').parents('.parent1')獲取上面哪一級父節點都可以。
$('li:parent')
子: $('#test span') 使用篩選條件
$('#test').find() 使用find()
$('#test').children('') 使用children()函數
兄弟:$('#test').siblings() 返回兄弟姐妹節點,不分前后
$('#test').prevAll() 返回所有之前的兄弟節點
$('#test').prev() 返回上一個兄弟節點,不是所有的兄弟節點
$('#test').next() 返回下一個兄弟節點,不是所有的兄弟節點
$('#test').nextAll() 返回所有之后的兄弟節點