01基本选择器
$(document).ready(function () {
$("#btn1").click(function () {
$("#one").css("background-color","red");
});
$("#btn2").click(function () {
$(".mini").css("background-color", "red");
});
$("#btn3").click(function () {
$("div").css("background-color", "red");
});
$("#btn4").click(function () {
$("*").css("background-color", "red");
});
$("#btn5").click(function () {
$("span,#two").css("background-color", "red");
});
});
02层次选择器
$(document).ready(function () {
$("#btn1").click(function () {
$("body div").css("background-color", "red");
});
$("#btn2").click(function () {
$("body>div").css("background-color", "red");
});
$("#btn3").click(function () {
$(".one+div").css("background-color", "red");
});
$("#btn4").click(function () {
$("#two~div").css("background-color", "red");
});
});
03基本过滤选择器
$(document).ready(function () {
$("#btn1").click(function () {
$("div:eq(0)").css("background-color", "red");
});
$("#btn2").click(function () {
$("div:last").css("background-color", "red");
});
$("#btn3").click(function () {
$("div:not(.one)").css("background-color", "red");
});
$("#btn4").click(function () {
$("div:even").css("background-color", "red");
});
$("#btn5").click(function () {
$("div:odd").css("background-color", "red");
});
$("#btn6").click(function () {
$("div:eq(2)").css("background-color", "red");
});
$("#btn7").click(function () {
$("div:gt(2)").css("background-color", "red");
});
$("#btn8").click(function () {
$("div:lt(2)").css("background-color", "red");
});
$("#btn9").click(function () {
$("*:header").css("background-color", "red");
});
$("#btn10").click(function () {
$("*:animated").css("background-color", "red");
});
});
04内容过滤选择器
$(document).ready(function () {
$("#btn1").click(function () {
$("div:contains('di')").css("background-color", "red");
});
$("#btn2").click(function () {
$("div:empty").css("background-color", "red");
});
$("#btn3").click(function () {
$("div[class='mini']").css("background-color", "red");
});
$("#btn4").click(function () {
$("div:parent").css("background-color", "red");
});
});
05属性选择器
$(document).ready(function () {
$("#btn1").click(function () {
$("div[title]").css("background-color", "red");
});
$("#btn2").click(function () {
$("div[title=test]").css("background-color", "red");
});
$("#btn3").click(function () {
$("div[title!=test]").css("background-color", "red");
});
$("#btn4").click(function () {
$("div[title^=te]").css("background-color", "red");
});
$("#btn5").click(function () {
$("div[title$=est]").css("background-color", "red");
});
$("#btn6").click(function () {
$("div[title*=es]").css("background-color", "red");
});
$("#btn7").click(function () {
$("div[id][title*=te]").css("background-color", "red");
});
});
06子元素过滤选择器
$(document).ready(function () {
$("#btn1").click(function () {
$("div.one :nth-child(2)").css("background-color", "red");
});
$("#btn2").click(function () {
$("div.one :first-child").css("background-color", "red");
});
$("#btn3").click(function () {
$("div.one :last-child").css("background-color", "red");
});
$("#btn4").click(function () {
$("div.one :only-child").css("background-color", "red");
});
});