Home > Web Front-end > JS Tutorial > jquery selector: last-child does not work solution

jquery selector: last-child does not work solution

黄舟
Release: 2017-06-23 14:59:22
Original
2004 people have browsed it

jquery :last-child doesn’t work? ? ?

Paste the source code

<!DOCTYPE html>
<html>
<head>
<style>
span.solast { text-decoration:line-through; }
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<div>
<span>John,</span>
<span>Karl,</span>
<span>Brandon,</span>
<span>Sam</span>
<div id="clearFloat"></div>

</div>
<div>
<span>Glen,</span>
<span>Tane,</span>

<span>Ralph,</span>
<span>David</span>
<div id="clearFloat"></div>

</div>
<script>
$("div span:last-child").css({color:"red", fontSize:"80%"})

</script>

</body>
</html>
Copy after login

Why is the sentence

$("div span:last-child").css({color:"red", fontSize:"80%"})
Copy after login

added after

Can't it take effect? Collapse

My purpose is to get the last span element
under each div and set the css style

$.each($("body>div"),function(i){
      $(this).children("span").last().<a href="https://www.baidu.com/s?wd=css&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLuyu9rjRkujNWnvfvrjIB0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHRLnWDzPj0Y" target="_blank" class="baidu-highlight">css</a>({color:"red", fontSize:"80%"})
  });
Copy after login

to

$("div span:last").css({color:"red", fontSize:"80%"})
Copy after login

Because the last child is no longer span.

My purpose is to get the last span element under each div
Using last can only match one element

The above is the detailed content of jquery selector: last-child does not work solution. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template