jQuery DOM Traversing 的小技巧

最近發現兩組對稱的selector , 很常用到, 記錄如下:

找尋下層元素方面:
  • children(): 只在子元素那層搜尋 (only travels a single level down the DOM tree) 
  • find(): 會不斷搜尋下去, 直到沒有再下層(traverse down multiple levels to select descendant elements)

找尋上層元素方面:

  • parent(): 只在父元素那層搜尋 ( only travels a single level up the DOM tree )
  • parents(): 會不斷搜尋下去, 直到沒有再上層 ( search through the ancestors of these elements in the DOM tree )


留言

熱門文章