element:根据元素的名称来获取元素 selector1,selector2:同时获取多个元素 .class:根据元素的 class 属性来获取元素 2、层级选择器(重点) ancetor descendant :选取祖先元素下的所有后代元素(多级) parent > child :选择父元素下的所有子元素(一级) prev + next :选取当前元素紧邻的下一个同级元素 prev~ sibling...
基本选择器包括5种选择器:#id、element、.class、*和selectorl,selector2.selectorN,下面将配合实例分别介绍每种选择器的作用及使用方法。 1.#id选择器(id选择器) #id选择器根据给定的ID匹配一个元素。如果选择器中包含特殊字符,可以用两个斜杠转义。 2.element选择器(标签选择器) element选择器是一个用于搜索...
示例:选择所有 "myElement" 元素内的段落元素 $('#myElement p'); 【3】子元素选择器(Child Selector) 选择某个元素的直接子元素。 示例:选择所有 "myElement" 元素的直接子元素中的段落元素 $('#myElement > p'); 【4】下一个兄弟元素选择器(Next Adjacent Selector) 选择紧接在指定元素后的下一...
:first-child 获取第一个子元素,不区分元素类型 :first-of-type1.9+ 获取第一个子元素,区分元素类型 :last-child 获取最后一个子元素,不区分元素类型 :last-of-type1.9+ 获取第一个子元素,区分元素类型 :nth-child 获取第n个子元素,不区分元素类型 :nth-last-child()1.9+ 获取倒数第n个子元素,不区分类型...
selector1,selector2,selectorN 匹配满足选择器的所有元素 层次选择器 elementParent elementChild 匹配elementParent下所有的子元素。 elementParent>elementChild 选择所有上级元素为elementParent的元素 prev+next 匹配prev同级之后紧邻的元素next prev~sibling 匹配prev同级之后的元素sibling ...
jQuery:nth-child()Selector ❮ jQuery Selectors Example Select each <p> element that is the third child of its parent: $("p:nth-child(3)") Try it Yourself » Definition and Usage The :nth-child(n) selector selects all elements that are thenth child, regardless of type, of their...
傳統DOM API 提供我們幾種找到特定元素的方法,如: getElementById()、getElementsByName()、getElementsByTagName()... 等等,若要由相對從屬關係去找,則要由 childNodes()、parentNode() 下手。遇到複雜一點的需求,例如要找出所有被包在 div 中 target="_blank" 的 <a>,以不變應萬變的寫法是先用 getElements...
With :nth-child(n), all children are counted, regardless of what they are, and the specified element is selected only if it matches the selector attached to the pseudo-class. With the .eq( n ) call only the selector attached to the pseudo-class is counted, not limited to children of...
$("Element:first") 'HTML页面中某类元素的第一个元素 $("Element:last") 'HTML页面中某类元素的最后一个元素 $("Element:not(selector)") '去除所有与给定选择器匹配的元素,如:$("input:not(:checked)") 表示选择所有没有选中的复选框 $("Element:even") '获得偶数行 ...
:first-child jQuery:first-childSelector ❮ jQuery Selectors Example Select every <p> element that is the first child of its parent: $("p:first-child") Try it Yourself » Definition and Usage The :first-child selector selects all elements that are the first child of their parent....