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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:15:02+00:00 2026-05-24T17:15:02+00:00

So I have the following structure: <div id=some id> <div> <input id=some other id

  • 0

So I have the following structure:

<div id="some id">
     <div>
          <input id="some other id" ....>
          .....bunch of other inputs with no id field....
          <select onclick="findSiblingWithId()">             
     </div>
     <div>
          <input id="some other id" ....>
          .....bunch of other inputs with no id field....
          <select onclick="findSiblingWithId()">             
     </div>
     <div>
          <input id="some other id" ....>
          .....bunch of other inputs with no id field....
          <select onclick="findSiblingWithId()">             
     </div>

So in my findSiblingWithId i don’t know the id I’m looking for, all I know is that for the other components in the same div, only one will have an id. How can I get that ?

Edit:
Since it seems I didnt explain well enough I’ll try to add more info. So I want for example when the select component changes (here it could be a button or anything, it doesnt matter) to get the corresponding <input id="some other id" ..> from the same div.

Like I tried to explain above, I have one huge div, the <div id="some id">, now this contains a number of smaller <div> without ids.

Each of these smaller divs will have ONE inputfield with an ID and a bunch of other without an ID. Now on an action, doesn’t matter if a button click or whatever, from a component located IN THE SAME div (I thought the correct work would be ‘sibling’) is there a way I can find the input that has an ID attribute?

Regards,
Bogdan

  • 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-24T17:15:02+00:00Added an answer on May 24, 2026 at 5:15 pm

    You could iterate over all children of the parent:

    function findSiblingWithId(element) {
        var siblings = element.parentNode.children,
            sibWithId = null;
        for(var i = siblings.length; i--;) {
            if(siblings[i].id) {
                sibWithId = siblings[i];
                break;
            }
        }
    
        if(sibWithId) [
            // found it
        }
    };
    

    You have to pass the clicked element (I hope you have a proper select field);

    <select onclick="findSiblingWithId(this)">    
    

    Consider to attach the event handler for the change event, if you want to have it triggered when the user selected a value.

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

Sidebar

Related Questions

I have the following HTML structure <div id=test-1-yay></div> ... bunch of code ... <div
I have two views in a Drupal page with the following structure: <div> <div>Some
I have the following structure in a form: <div class='full'> <div class='half'> <label>Book</label> <select
I have the following structure: <div id=wrapper> <div id=div1>Some content</div> <div id=div2>Some content</div> </div>
I have some HTML with the following approximate structure and positioning: <div class=grand-parent style=position:
I have the following structure: <div id=container> <div id=someid1 style=float:right></div> <div id=someid2 style=float:right></div> <div
I have the following HTML structure: $('#subgroup a').nextUntil('h3').wrapAll('<div></div>'); <script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js></script> <div id=subgroup> <h3>Group name
I have the following HTML node structure: <div id=foo> <div id=bar></div> <div id=baz> <div
Hey Guys, i have created the following Menu Structure: <div id=menu> <ul> <li><a href=#>Main
So i have the following structure <div id=container> <div id=head></div> <div id=body></div> <div id=foot></div>

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.