$("ul li:first") 每个 <ul> 的第一个 <li> 元素
$("[href$='.jpg']") 所有带有以 ".jpg" 结尾的属性值的 href 属性
$("div#intro .head") id="intro" 的 <div> 元素中的所有 class="head" 的元素
使用 toggle() 方法来切换 hide() 和 show() 方法。
$("button").click(function(){
$("p").toggle();
});
text() - 设置或返回所选元素的文本内容
html() - 设置或返回所选元素的内容(包括 HTML 标记)
val() - 设置或返回表单字段的值
获取属性 - attr()
$("#w3s").attr("href");
$("#test1").text("Hello world!");
$("#test2").html("<b>Hello world!</b>");
$("#test3").val("Dolly Duck");
$("#w3s").attr("href","http://www.w3school.com.cn/jquery");
jQuery append() 方法在被选元素的结尾插入内容。
$("p").append("Some appended text.");
jQuery prepend() 方法在被选元素的开头插入内容。
$("p").prepend("Some prepended text.");
jQuery after() 方法在被选元素之后插入内容。
jQuery before() 方法在被选元素之前插入内容。
$("img").after("Some text after");
$("img").before("Some text before");
jQuery remove() 方法删除被选元素及其子元素。
$("#div1").remove();
jQuery empty() 方法删除被选元素的子元素。
$("#div1").empty();
•addClass() - 向被选元素添加一个或多个类
•removeClass() - 从被选元素删除一个或多个类
•toggleClass() - 对被选元素进行添加/删除类的切换操作
•css() - 设置或返回样式属性
将返回首个匹配元素的 background-color 值:
$("p").css("background-color");
将为所有匹配元素设置 background-color 值:
$("p").css("background-color","yellow");
$("p").css({"background-color":"yellow","font-size":"200%"});
width() 方法设置或返回元素的宽度(不包括内边距、边框或外边距)。
height() 方法设置或返回元素的高度(不包括内边距、边框或外边距)。
innerWidth() 方法返回元素的宽度(包括内边距)。
innerHeight() 方法返回元素的高度(包括内边距)。
outerWidth() 方法返回元素的宽度(包括内边距和边框)。
outerHeight() 方法返回元素的高度(包括内边距和边框)。
设置指定的 <div> 元素的宽度和高度:
$("#div1").width(500).height(500);