How to use JQuery to focus on a specific DIV tag?
Say I got a few DIV tags in a HTML page like:
<DIV ID="all">
<DIV ID="div1">
<Input type="radio" name="data['site1']['user']" VALUE="1">user1<br/>
</DIV>
<DIV ID="div2">
<Input type="radio" name="data['site1']['user']" VALUE="2">user2<br/>
</DIV>
<DIV ID="div3">
<Input type="radio" name="data['site1']['user']" VALUE="3">user3<br/>
</DIV>
<DIV ID="div4">
<Input ty开发者_Python百科pe="radio" name="data['site1']['user']" VALUE="4">user4<br/>
</DIV>
</DIV>
Is it possible to do the same effect in JQuery like this:
Document.getElementByID('div2').focus();
The equivalent of that is:
$("#div2").focus();
but you can only focus on a form element so:
$("#div2 :input").focus();
will focus on the first form element inside the element with ID div2.
You can't set focus on div
elements, only the following elements are "focusable":
A
AREA
LABEL
INPUT
SELECT
TEXTAREA
BUTTON
If you have some element that can receive focus inside your div, get it with your selector, otherwise, the most similar behavior I could think, is scrolling to the element...
You can't focus on a div. But if you want to focus on the radio button within div2, you can try:
$('#div2 input').focus();
精彩评论