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>
Why is the sentence
$("div span:last-child").css({color:"red", fontSize:"80%"})
added after
Can't it take effect? CollapseMy 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%"}) });
to
$("div span:last").css({color:"red", fontSize:"80%"})
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!