Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6869065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:30:42+00:00 2026-05-27T03:30:42+00:00

I don’t understand what am I doing wrong. I have the following html element:

  • 0

I don’t understand what am I doing wrong. I have the following html element:

<div id="accordion">
    <h3>
        <a href="#">Section 1</a></h3>
    <div>
        <p>
            Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer ut neque.
            Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc. Nam a
            nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut odio. Curabitur malesuada.
            Vestibulum a velit eu ante scelerisque vulputate.
        </p>
    </div>
    <h3>
        <a href="#">Section 2</a></h3>
    <div>
        <p>
            Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet purus. Vivamus
            hendrerit, dolor at aliquet laoreet, mauris turpis porttitor velit, faucibus interdum
            tellus libero ac justo. Vivamus non quam. In suscipit faucibus urna.
        </p>
    </div>                                    
</div>

this element (<div id='accordion'>) clearly shows that it’s first child is the h3 tag the next child is the div tag then the h3 etc

I want to select the fist child of this div. In other words I want to select the first h3 tag

as a result I have tried:

    $("#accordion:first-child").css("font-size","30px");

also

     $("#accordion:first").css("font-size","30px");

both ways applies a font of 30px to the main div element (<div id='accordion'>)

what am I doing wrong I want to only select the first child of the accordion it clearly is the h3 tag

Edit

whow I was just missing a space. this page did not includes the pace.

I had to change my code from

$("#accordion:first").css("font-size","30px");

TO

$("#accordion :first").css("font-size","30px");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:30:43+00:00Added an answer on May 27, 2026 at 3:30 am

    You have to separate the id of the parent from the :first-child selector. Also, the frst-child selector will select all the first-child elements, not only one. To select only one you have to use the :first selector.

    $("#accordion h3:first").css("font-size","30px");
    

    This is the way css selectors (which jQuery heavily uses) works.

    Take a read at css descendant selector here.

    At times, authors may want selectors to match an element that is the descendant of another element in the document tree (e.g., “Match
    those EM elements that are contained by an H1 element”). Descendant
    selectors express such a relationship in a pattern. A descendant
    selector is made up of two or more selectors separated by white
    space
    .

    Also, according to the jQuery docs, there are better methods to retrieve the first child of an element, to achieve better performance.

    Because :first is a jQuery extension and not part of the CSS
    specification, queries using :first cannot take advantage of the
    performance boost provided by the native DOM querySelectorAll()
    method. To achieve the best performance when using :first to select
    elements, first select the elements using a pure CSS selector, then
    use .filter(“:first”).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if it's I'm doing it wrong or if there's a bug (I
Don't yell at me! i have seen many threads claiming that HTML cannot be
Don't you hate it when you have class Foobar { public: Something& getSomething(int index)
I don't understand where the extra bits are coming from in this article about
I don't want PHP errors to display /html, but I want them to display
Don't think that I'm mad, I understand how php works! That being said. I
Don't they both have to convert to machine code at some point to execute
I don't want my user to even try downloading something unless they have Wi-Fi
I don't understand why this code doesn't work: function Messages(type,text) { console.log(In function Message);
Don't overthink this - there's a very commonly used term and I ... have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.