المحدد :last-child
في jQuery
< jQuery
اذهب إلى التنقل
اذهب إلى البحث
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
المحدد :last-child
الوصف
يختار هذا المحدِّد جميع العناصر التي تُعدُّ الابن الأخير لآبائها.
jQuery( ":last-child" )
أُضيف مع الإصدار: 1.1.4.
يختار المحدد :last عنصرًا وحيدًا فقط، بينما يمكن أن يختار المحدد :last-child
عدة عناصر إذ يكون لكل أب عنصرًا واحدًا منها.
أمثلة
إيجاد العنصر <span>
الأخير في كل عناصر <div>
المتطابقة وتغيير تنسيقها وإضافة بعض التأثيرات التفاعلية إليها (عند مرور مؤشر الفأرة عليها):
<!doctype html>
<html lang="ar">
<head>
<meta charset="utf-8">
<title>last-child مثالٌ عن استعمال المحدد</title>
<style>
span.solast {
text-decoration: line-through;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div>
<span>أحمد،</span>
<span>بشير،</span>
<span>عبد الله،</span>
<span>عمر</span>
</div>
<div>
<span>سيرين،</span>
<span>شذى،</span>
<span>مارية،</span>
<span>فاطمة</span>
</div>
<script>
$( "div span:last-child" )
.css({ color:"red", fontSize:"80%" })
.hover(function() {
$( this ).addClass( "solast" );
}, function() {
$( this ).removeClass( "solast" );
});
</script>
</body>
</html>