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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:04:46+00:00 2026-06-19T04:04:46+00:00

I have a form element like this: <div id=myformelement> <input type=radio id=option1> <label for=option2>Option

  • 0

I have a form element like this:

<div id="myformelement">
   <input type="radio" id="option1">
   <label for="option2">Option 1</label>
   <input type="radio" id="option2">
   <label for="option2">Option 2</label> 
   <input type="radio" id="option3">
   <label for="option3">Option 3</label> 
   <input type="radio" id="option4">
   <label for="option4">Option 4</label>  
</div>

I want to hide the input fields “option2” and “option3” and their labels.

I can hide the input bullets by addressing the id. Unfortunately the corresponding labels to the input fields only have a “for” tag with the id in it.

How can I do this with javascript (no jquery).

I found this question (Find html label associated with a given input), but this seems only to work with one label within an ID, I can not use this.

Thanks in advance!
Kind regards,
Malte

  • 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-19T04:04:47+00:00Added an answer on June 19, 2026 at 4:04 am

    You can do it with nextSibling:

    var rdo = document.getElementById("option2");
    var lbl;
    
    rdo.style.display = "none";
    for (lbl = rdo.nextSibling; lbl && lbl.nodeName.toUpperCase() !== "LABEL"; lbl = lbl.nextSibling) {
    }
    if (lbl) {
        lbl.style.display = "none";
    }
    

    But I have a better option for you: It seems to be a well-kept secret that label elements can contain the input they relate to, and when they do no for is required at all. So if you change your HTML to:

    <div id="myformelement">
       <label><input type="radio" id="option1"> Option 1</label>
       <label><input type="radio" id="option2"> Option 2</label> 
       <label><input type="radio" id="option3"> Option 3</label> 
       <label><input type="radio" id="option4"> Option 4</label>  
    </div>
    

    …it gets a lot easier:

    document.getElementById("option2").parentNode.style.display = "none";
    

    You just find the input, traverse up to its parent which is the label, and hide that (which will hide the input as well).

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

Sidebar

Related Questions

Okay so say I have a form element like this: HTML: <div class=form-item> <label>Current
I have an Element Like <div class=control> <label>&nbsp;</label> <input type=checkbox id=1><span class=controlText>Check Box</span> <div
i have a form with multiple div elements like this <div> <label for=id>text</label> <input
Suppose to have a code like this: <div class=notSelected> <label>Name <input type=text name=name id=name
I have html like this: <form action= id=emailFillOutForm> <div class=txt-fld> <label for=repName>Rep. Name</label> <input
I have a HTML script like this: <form id=no1> <input id=title type=text /> <input
I have a form element defined as: <div class=field> <div class=name> <label for=User_LastName> Last
i have a template that looks something like this. Sample Template <div id="form-entry"> <h4>Some
I have an div element <div id=form><form id=formstuff>form input stuff</div></div> that shows/hides (or toggles)
I have a Zend_Form with file element like this: ->addElement('file', 'image', array( 'required' =>

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.