Search code examples
javascripthtmldomdhtml

How to move the cursor into a input text box by clicking a label tag?


How to move the cursor position into a input text box by clicking a label tag?


Solution

  • Use the for attribute. No need for any Javascript.

    <label for="name">Name</label><input type="text" id="name" name="name" />
    

    The browser will do the magic all by itself.