Forums

This topic contains 9 replies, has 0 voices, and was last updated by  ysamjo 9 years, 12 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #23908

    ysamjo
    Member

    Hi there,

    I want the Selector for the first occurence on thte whole page of a specific class (let’s say "foo"). I don’t know the exact ancestor.

    Is there a Pseudo-Selector that I’m missing?

    #52977

    ysamjo
    Member

    Yay, i’ve been aware of :first-child, but foo:first-child matches the first child from foo and not foo itself, doesn’t it?

    #53247

    ysamjo
    Member

    Well that’s my problem…

    To clarify:

    <div class="foo">
    <p>text</p>
    <p>text</p>
    <p>text</p>
    <p>text</p>
    <p>text</p>
    </div>

    <div class="foo">
    <p>text</p>
    <p>text</p>
    <p>text</p>
    <p>text</p>
    <p>text</p>
    </div>

    And now I don’t want to make the first p bold, but the first div. And as I said I don’t know the upper element of the dix class.

    #53263

    iopet
    Member

    Wrap the .foo divs inside another div, like so:

    Code:

    text

    text

    text

    text

    text

    text

    text

    text

    text

    text

    text

    text

    text

    text

    text

    Then add:

    Code:
    #lotsafoos .foo:first-child{font-weight:700}

    or using jQuery

    Code:
    $(function(){
    $(“#lotsafoos .foo:first”).css(“font-weight”,”700″);
    });
    #53338

    jocke76
    Member

    Hey

    Maybe the thread is dead .. anyways..
    and maybe you only want the css-sollution..

    But with javascript you could…

    … According to w3c

    Quote:
    The getElementById() method returns a reference to the first object with the specified ID.

    (http://www.w3schools.com/HTMLDOM/met_doc_getelementbyid.asp)

    It don’t know how reliable that is though..

    /Jocke

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

icon-link icon-logo-star icon-search icon-star