Jquery獲取子類,同級類 第幾個元素

2021-10-03 07:29:30 字數 745 閱讀 8380

$('.test').parent();//父節點

$('.test').parents();//全部父節點

$('.test').parents('.test1');//含有類名.test1的父節點

$('.test').children();//全部子節點

$('.test').children('li');//元素為li的全部子節點

$('.test').prev();//上乙個兄弟節點

$('.test').prevall();//之前所有兄弟節點

$('.test').next();//下乙個兄弟節點

$('.test').nextall();//之後所有兄弟節點

$('.test').siblings();//所有兄弟節點

$('.test').siblings('.test1');//含有類名.test1的所有兄弟節點

$('.test').find('.test1');//返回被選元素含有類名為.test1的所有後代元素;(返回全部用 * ,多個引數用 , 隔開)

$('.test').contents();//返回元素裡面所有內容,包括文字和節點

$('.test').contents('.test1');

test1

test3

test3_2

test3_3

test4

test5

test6

jQuery獲取父子同級元素

1.獲取父級元素 id parent 獲取其父級元素 id parents 獲取其所有的祖先元素 id closest 獲取其最近的祖先元素,依次上溯 2.獲取同級元素 id next selector 獲得匹配元素緊鄰的下乙個同胞元素。如果提供選擇器,則取回匹配該選擇器的下乙個同胞元素。id ne...

jquery獲取父元素子元素同級元素

一 獲取父級元素 1 parent expr 獲取指定元素的所有父級元素 href fir href sec href thr href fiv document ready function 獲取指定元素的下乙個同級元素 注意是下乙個同級元素哦 這個例子的結果是,只有list item 4背景色變...

jquery獲取父元素 同級元素 子元素

jquery.parent expr 找父親節點,可以傳入expr進行過濾,比如 span parent 或者 span parent class jquery.parents expr 類似於jquery.parents expr 但是是查詢所有祖先元素,不限於父元素 jquery.childre...