SelectorExampleSelects * $("*") All elements #id $("#lastname") The element with id="lastname" .class $(".intro") All elements with class="intro" .class,.class $(".intro,.demo") All elements with the class "intro" or "demo" element $("p") All <p> elements el1,el2,el3...
linkSelecting Elements by Class Name 1 $(".myClass"); linkSelecting Elements by Attribute 1 $("input[name='first_name']"); linkSelecting Elements by Compound CSS Selector 1 $("#contents ul.people li"); linkSelecting Elements with a Comma-separated List of Selectors ...
Selects all elements of type file. Also in:Selectors>Child Filter :first-child Selector Selects all elements that are the first child of their parent. Also in:Selectors>Child Filter :first-of-type Selector Selects all elements that are the first among siblings of the same element name. ...
1)首先我们要在body里面写我们需要测试的标签。 1<body>2<input type="button"value="点击修改小苹果"id="btnChangeOne"/>3<input type="button"value="点击修改所有标签"id="btnChangeAll"/>4<ul id="ulList">5<liclass="fruit"> 小苹果</li>6<liclass="fruit"> 大香蕉</li>7<li > 小南瓜</li...
$("Element:first") 'HTML页面中某类元素的第一个元素 $("Element:last") 'HTML页面中某类元素的最后一个元素 $("Element:not(selector)") '去除所有与给定选择器匹配的元素,如:$("input:not(:checked)") 表示选择所有没有选中的复选框 $("Element:even") '获得偶数行 ...
('.first')); 结果: <div class="container"> <div class="inner second">And</div> <div class="inner first">Hello</div> </div> replaceAll(selector) 描述: 把所有的段落标记替换成加粗标记 HTML 代码: <p>Hello</p><p>cruel</p><p>World</p> jQuery 代码: $("<b>Paragraph. </b>")...
$(document)//选择整个文档对象$('#myId')//选择ID为myId的网页元素$('div.myClass')//选择class为myClass的div元素$('input[name=first]')//选择name属性等于first的input元素 也可以是jQuery特有的表达式: $('a:first')//选择网页中第一个a元素$('tr:odd')//选择表格的奇数行$('#myForm :input'...
index([selector|element]):搜索匹配的元素,并返回相应元素的索引值,从0开始计数。如果参数是一组DOM元素或者jQuery对象,那么返回值就是传递的元素相对于原先集合的位置。如果不传递参数,那么返回值就是这个jQuery对象集合中第一个元素相对于其同辈元素的位置。
replaceWith(content|fn) replaceAll(selector) 删除 empty() remove([expr]) detach([expr]) 复制 clone([Even[,deepEven]]) 筛选 过滤 eq(index|-index) first() last() hasClass(class) filter(expr|obj|ele|fn) is(expr|obj|ele|fn)
.class返回具有匹配的 CSS 类的所有元素。 *返回页中的所有元素。 selector1,| selectorN应用所有给定基本的选择器,并返回组合的结果。 上级后代给定的上级选择器,将返回匹配后代选择器的所有后代的元素的集合。 是例如"div p"将返回一个 <div> 中的所有 <p> 元素。