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 8353625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:19:08+00:00 2026-06-09T09:19:08+00:00

I am dynamically grabbing a selected drop down option’s text from an array of

  • 0

I am dynamically grabbing a selected drop down option’s text from an array of divs. When I do this:

$("#divID").children("select").eq(0).find('option:selected').text();

Everything works fine. However, when I do this:

$("#divID").children("select option:selected").eq(0).text();

It does not grab the text as expected. I was wondering what I am doing wrong with the latter approach to getting the text. Thanks.

JSFiddle – First Approach (Works)

JSFiddle – Second Approach (Doesn’t Work)

  • 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-06-09T09:19:09+00:00Added an answer on June 9, 2026 at 9:19 am

    The problem with what you are doing is your use of children.

    If you were to change children to find then it works perfectly. The reason is that children only finds elements that are direct children of the set being acted on. So it will only return things that are direct children of #divID. As you can see the option elements are not direct children so they can’t be returned.

    $("#divID").find("select option:selected").eq(0).text();
    

    See http://jsfiddle.net/nzhaD/5/

    Of course there are some subtle differences between the two of these. Cosnider this HTML:

    <div id="divLocation">
        <div>            
            <select id="1"/>
        </div>
        <select id="2"/>
    </div>
    

    I’ve cut the options out but your original selector will get id #2 (since it is the only select that is a child of #divLocation whereas mine would get the first selected option which will be presumably in id #1.

    So the moral of the story is do whichever selector does what you actually want it to. 🙂

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

Sidebar

Related Questions

Im having trouble working grabbing a dynamically created image from this service: http://opsin.ch.cam.ac.uk/opsin/USER-STRUCTURE-TO-GENERATE.png Im
I am grabbing a block of text, and within this block there will be
After dynamically creating a client-side table based on SELECT information retrieved from MySql database,
I am dynamically grabbing image links from a database and inserting them into image
I have a Sharepoint site that is dynamically grabbing a name and description from
I'm attempting to call the msgs.loginUsername property, by dynamically grabbing loginUsername from the html
Im dynamically creating divs with a button using this function var counter = 1;
I´m dynamically creating an instance of a class with reflection and this works fine,
I am dynamically appending and removing substring from NSString - At specific action I
I dynamically created a table with three columns. <tr> <td>1</td> <td>SegName</td> <td><input type='text' /></td>

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.