русский  עברית
tadam logo
דוגמאות jQuery
מצאתם שגיאה?
סמנו אותה עם העכבר ותלחצו
Ctrl + Enter
בדיקת כתיב Xhtml.co.il
Orphus system

סלקטור last-child

תיאור: תואם לכל האלמנטים שהם ילדים אחרונים אצל ההורים.

jQuery(':last-child')

הוספה בגרסה: 1.1.4

בזמן ש- :last תואם רק אלמנט אחד, סלקטור :last-child יכול להתאים ליותר מאחד: אחד לכל הורה.

דוגמאות

מחפש אלמנט span אחרון בכל div ומוסיף אליו סגנונות CSS.
    $("div span:last-child")
        .css({color:"red", fontSize:"80%"})
        .hover(function () {
              $(this).addClass("solast");
            }, function () {
              $(this).removeClass("solast");
            });
תוצאת הפעלה קוד לעיל:
קוד מלא:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
  <script>
  $(document).ready(function(){
    $("div span:last-child")
    $("div span:last-child")
        .css({color:"red", fontSize:"80%"})
        .hover(function () {
              $(this).addClass("solast");
            }, function () {
              $(this).removeClass("solast");
            });
  });
  </script>
  <style>
  span.solast { text-decoration:line-through; }
  </style>
</head>
<body>
  <div>
    <span>John,</span>
    <span>Karl,</span>
    <span>Brandon,</span>
    <span>Sam</span>
  </div>
  <div>
    <span>Glen,</span>
    <span>Tane,</span>
    <span>Ralph,</span>
    <span>David</span>
  </div>
</body>
</html>
האם מידע זה היה מועיל?
   

תגובות