- //选择第一个div元素.
- $("#btn1").click(function() {
- $("div:first").css("background-color", "aqua");
- });
- //选择最后一个div元素.
- $("#btn2").click(function() {
- $("div:last").css("background-color", "red");
- });
- //选择class不为one的 所有div元素.
- $("#btn3").click(function() {
- $("div:[class!='one']").css("background-color", "blue");
- });
- //选择 索引值为偶数 的div元素。
- $("#btn4").click(function() {
- $("div:even").css("background-color", "#fdeecc");
- });
- //选择 索引值为奇数 的div元素。
- $("#btn5").click(function() {
- $("div:odd").css("background-color", "#feec00");
- });
- //选择 索引等于 3 的元素
- $("#btn6").click(function() {
- $("div.*:eq(3)").css("background-color", "coral");
- });
- //选择 索引大于 3 的元素
- $("#btn7").click(function() {
- $("div:gt(3)").css("background-color", "orange");
- });
- //选择 索引小于 3 的元素
- $("#btn8").click(function() {
- $("div:lt(3)").css("background-color", "orchid");
- });
- //选择 所有的标题元素.比如h1, h2, h3等等...
- $("#btn9").click(function() {
- $(":header").css("background-color", "gold");
- });
- //选择 当前正在执行动画的所有元素.
- $("#btn10").click(function() {
- $(":animated").css("background-color", "#acdf45");
- });