Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery onclick function to focus input

I want a JQuery function that means if the user clicks on some text on the page it focuses an input.

$(document).ready(function(){
$('#header.search span').click(function(){
    $('#header.search input').focus();
});
});

That did not do anything. On Firebug nothing is registered.

Any ideas?

Marvellous

like image 594
Robin I Knight Avatar asked Sep 02 '11 14:09

Robin I Knight


1 Answers

http://jsfiddle.net/HenryGarle/LXngq/

<span>
    <br>
        Span
    <br>
    <input id="InputToFocus" type="text">
</span>

$('span').click(function(){
    $('#InputToFocus').focus();
});

Seems to be working fine, It is probably a problem with your selectors. Could you post the structure of your HTML surrounding the input?

like image 87
Henry Avatar answered Sep 28 '22 07:09

Henry