Clicking a shortcut does not open

I always thought that clicking on labelwould more or less trigger a click on the corresponding form element. However, this does not work when it comes to select. Work "mousedown-on-selectfield" -animation works, but the selection does not open.

I tried this:

<label for="my_id">Click me</label>
<select id="my_id">
  <option>1</option>
  <option>2</option>
</select>

So what:

<label for="my_id">Click me
  <select id="my_id">
    <option>1</option>
    <option>2</option>
  </select>
</label>

Any idea what I'm doing wrong?

PS: Imo there shouldn't be any Javascript here, as this is an html function

+4
source share
1 answer

Like W3C, clicking on a shortcut may do nothing or send the onFocus event to the corresponding field. In this case, as a rule, it calls onFocus on the select element.

https://www.w3.org/TR/html5/forms.html#the-label-element label click

+2

Source: https://habr.com/ru/post/1608015/


All Articles