rolling stone rolling stone - 1 year ago 219
HTML Question

How to Set Focus on Input Field using JQuery

Given the following HTML structure:

<div class="wrapper">
<div class="top">
<a href="" class="link">click here</a>
<div class="middle">
some text
<div class="bottom">
<input type="text" class="post">
<input type="submit">

which will be repeated several times on the page, how do I set the focus on the input field in the
div when a user clicks on the link in the

I am currently making the
div appear successfully on click using the JQuery code below, but can't seem to figure out how to set focus on the input field at the same time.

$('.link').click(function() {


Answer Source

Try this, to set the focus to the first input field:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download