0

Trying to give focus to a styled select and other inputs nested within divs:

<label for="focusedSelect">I want to Focus on You</label>
<div class="styled-select">
    <select id="focusedSelect">
        <option value="1">Won</option>
        <option value="2">Too</option>
    </select>
</div>

<label for="focusedInput>Let me Focus on You Too</label>
<div class="styled-inputs">
    <input id="focusedInput" type="text"/>
</div>

Clicking the label doesn't give focus to input or select of nested div.

4
  • 1
    What is your question? Commented Jul 11, 2016 at 22:31
  • Trying to give focus to a styled select and other inputs nested within divs Commented Jul 11, 2016 at 23:37
  • label for not focusing on input / select nested within a div Commented Jul 11, 2016 at 23:38
  • You have no styles, so it is hard to test. I made a CodePen and the <label>s do what they should do — clicking them puts focus on the associated field. Your question is still not clear, however. Commented Jul 11, 2016 at 23:47

1 Answer 1

2

Your code is working fine for me, I just had to fix a few mistakes:

<label for="focusedSelect">I want to Focus on You</label>
<div class=" styled-select">
  <select id="focusedSelect">
    <option value="1 ">Won</option>
    <option value="2 ">Too</option>
  </select>
</div>

<label for="focusedInput">Let me Focus on You Too</label>
<div class="styled-inputs">
  <input id="focusedInput" type="text" />
</div>

You were missing the trailing quote on both label "for" attributes as well as the trailing greater than (>) character on the closing <label> element for the second input.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.