:first-child Selector in JQuery


version added: 1.1.4jQuery(‘:first-child’)

While :first matches only a single element, the :first-child selector can match more than one: one for each parent. This is equivalent to :nth-child(1).


Finds the first span in each matched div to underline and add a hover state.

<!DOCTYPE html>
  span { color:#008; }
  span.sogreen { color:green; font-weight: bolder; }
  <script src="/scripts/jquery-1.4.js"></script>


    $("div span:first-child")
        .css("text-decoration", "underline")
        .hover(function () {
            }, function () {


Leave a Reply

Your email address will not be published. Required fields are marked *