المحدد ‎‎‎:last-of-type‎ في 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-of-type

الوصف

يختار هذا المحدِّد جميع العناصر التي يُعدُّ كل واحد منها العنصر الأخير بين أخوته التي لها الاسم ذاته.

jQuery( ":last-of-type" )‎

أُضيف مع الإصدار: 1.9.

يطابق المحدِّد ‎:last-of-type العناصر التي لا تملك عناصر أخرى ولها الأب نفسه واسم العنصر نفسه أيضًا في الصفحة.

أمثلة

إيجاد العنصر <span> الأخير في كل عناصر <div> المتطابقة وتغيير تنسيقها وإضافة بعض التأثيرات التفاعلية إليها (عند مرور مؤشر الفأرة عليها):

<!doctype html>
<html lang="ar">
<head>
  <meta charset="utf-8">
  <title>last-of-type مثالٌ عن استعمال المحدد</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>
  <b>فاطمة</b>
</div>
 
<script>
$( "span:last-of-type" )
  .css({ color:"red", fontSize:"80%" })
  .hover(function() {
    $( this ).addClass( "solast" );
  }, function() {
    $( this ).removeClass( "solast" );
  });
</script>
 
</body>
</html>

مصادر