jQuery Basic Filter Selector Instance Code
- 2021-07-16 01:45:01
- OfStack
In this paper, we share the specific code of jQuery basic filter selector for your reference. The specific contents are as follows
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="imooc.css" type="text/css">
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>
<body>
<h2> Basic filter </h2>
<h3>:first/:last/:even/:odd</h3>
<div class="left">
<div class="div">
<p>div:first</p>
<p>:even</p>
</div>
<div class="div">
<p>:odd</p>
</div>
<div class="div">
<p>:even</p>
</div>
<div class="div">
<p>:odd</p>
</div>
<div class="div">
<p>:even</p>
</div>
<div class="div">
<p>div:last</p>
<p>:odd</p>
</div>
</div>
<script type="text/javascript">
// Find the first 1 A div
$(".div:first").css("color", "#CD00CD");
</script>
<script type="text/javascript">
// Find the last 1 A div
$(".div:last").css("color", "#CD00CD");
</script>
<script type="text/javascript">
//:even Select an element whose cited value is even, from the 0 Start counting
$(".div:even").css("border", "3px groove red");
</script>
<script type="text/javascript">
//:odd Select an element whose cited value is odd, from the 0 Start counting
$(".div:odd").css("border", "3px groove blue");
</script>
<h3>:eq/:gt/:lt</h3>
<div class="left">
<div class="aaron">
<p>:lt(3)</p>
</div>
<div class="aaron">
<p>:lt(3)</p>
</div>
<div class="aaron">
<p>:eq(2)</p>
</div>
<div class="aaron">
</div>
<div class="aaron">
<p>:gt(3)</p>
</div>
<div class="aaron">
<p>:gt(3)</p>
</div>
</div>
<script type="text/javascript">
//:eq
// Select a single
$(".aaron:eq(2)").css("border", "3px groove blue");
</script>
<script type="text/javascript">
//:gt Select all index values in the matching collection greater than the given index Elements of parameters
$(".aaron:gt(3)").css("border", "3px groove blue");
</script>
<script type="text/javascript">
//:lt Select that all index values in the matching collection are less than the given index Elements of parameters
// And :gt On the contrary
$(".aaron:lt(2)").css("color", "#CD00CD");
</script>
<h3>:not</h3>
<div class="left">
<div>
<input type="checkbox" name="a" />
<p>Aaron</p>
</div>
<div>
<input type="checkbox" name="b" />
<p> Massive open online course </p>
</div>
<div>
<input type="checkbox" name="c" checked="checked" />
<p> Others </p>
</div>
</div>
<script type="text/javascript">
//:not Select All Elements to remove elements that do not match the given selector
// Select all followed by none checked Property of input Element after the p Element, give color
$("input:not(:checked) + p").css("background-color", "#CD00CD");
</script>
</body>
</html>