If we just get one of the first Li in UL, then we can write this:
$ ("ul Li:first");
$ ("ul Li"). EQ (0);
$ ("ul Li").
$ ("ul Li"). Slice (0,1);//slice the position at which the first parameter represents the selection, and the second argument is the ending position
<ul>
<li> Anne Zhe </li>
<li> Anne Zhe </li>
<li> Anne Zhe </li>
<li> Anne Zhe </li>
</ul>
<ul>
<li> Anne Zhe </li>
<li> Anne Zhe </li>
< Li> Anne Zhe </li>
<li> Anne Zhe </li>
</ul>
<ul>
<li> Anne Zhe </li>
<li> Anne Zhe </li>
<li> Anne Zhe </li>
<li> Anne Zhe </li>
</ul>
<ul>
<li> Anne Zhe </li>
<li> Anne Zhe </li>
<li> Anne Zhe </li>
<li > Anne Zhe </li>
</ul>
Solution I've probably written four of them.
<script type= "Text/javascript" >
//Scheme a
$ (function () {
var list=$ ("ul");
for (var i = 0; i < list.length i++) {
$ ("Ul:eq (" +i+) Li:first "). CSS (" Background "," Red ");
}
);
Scenario two
/*$ (function () {
$ ("ul"). each (function () {
$ (this). Children (). (). A (). CSS ("Background", "red") );
});
}); *
//Scheme three
/*$ (function () {
$ ("ul Li:nth-child (1)"). CSS ("Background", "Red");
}); *
///scheme four
/*$ (function () {
$ ("ul Li:first-child"). CSS ("Background", "Red");
}); * *
</script>
Run results
The above is the entire content of this article, I hope to help you, thank you for the support of cloud habitat community!