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

סלקטור first-child

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

jQuery(':first-child')

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

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

דוגמאות

מחפש אלמנט span ראשון בכל div, מוסיף אליו סגנונות.
    $("div span:first-child")
        .css("text-decoration", "underline")
        .hover(function () {
              $(this).addClass("sogreen");
            }, function () {
              $(this).removeClass("sogreen");
            });
תוצאת הפעלה קוד לעיל:
קוד מלא:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>  
  <script>
  $(document).ready(function(){    
    $("div span:first-child")
        .css("text-decoration", "underline")
        .hover(function () {
              $(this).addClass("sogreen");
            }, function () {
              $(this).removeClass("sogreen");
            });
  });
  </script>
  <style>
  span { color:#008; }
  span.sogreen { color:green; font-weight: bolder; }
  </style>
</head>
<body>
  <div>
    <span>John,</span>
    <span>Karl,</span>
    <span>Brandon</span>
  </div>
  <div>
    <span>Glen,</span>
    <span>Tane,</span>
    <span>Ralph</span>
  </div>
</body>
</html>
האם מידע זה היה מועיל?
   

תגובות