Search code examples
javascriptjqueryfocusfocusin

jquery: when i click a div, give focus to a textbox


$('.my-button').click(function() {
    $(".my-textbox").focus()
});

Before Jquery 1.4 this used to be the way to call focus to a textbox, now it doesn't work. When I click the button, I want to call focus to the textbox, what i mean by "focus", is that I want the textbox to act like it was just clicked on, so that the user will not have to click on the textbox.

.focus is supposed to do an auto click onto the textbox i want it to, why isn't it working now? it broke in Jquery 1.4. I just need to know how to do it.


Solution

  • It still works. See here.

    reference: jQuery focus docs

    As mentioned there, calling 'focus' on one element may trigger 'blur' on another - and so use 'focusin' instead.