JQuery選擇器 大於 空格 波浪線 加號的區別
元素遍歷
符號 | 說明 |
---|---|
空格 | $(‘parent child’)表示獲取parent下的所有的child節點(所有的子孫)。 |
大於號 | $(‘parent > child’)表示獲取parent下的所有叫child的兒子(第一代)。 |
加號 | $(‘pre + nextbrother’)表示獲得pre節點的下一個兄弟節點,相當於next()方法 |
波浪號 | $(‘pre ~ brother’)表示獲取pre節點的後面的所有兄弟節點,相當於nextAll()方法。 |
參見 Jquery API
Child Selector (“parent > child”)
Selects all direct child elements specified by “child” of elements specified by “parent”.
Descendant Selector (“ancestor descendant”)
Selects all elements that are descendants of a given ancestor.
Next Adjacent Selector (“prev + next”)
Selects all next elements matching “next” that are immediately preceded by a sibling “prev”.
Next Siblings Selector (“prev ~ siblings”)
Selects all sibling elements that follow after the “prev” element, have the same parent, and match the filtering “siblings” selector.
Attribute Contains Prefix Selector [name|=”value”]
Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-).