Reputation: 1629
Trying to select the input inside the tr previously selected and add focus to it.
Here's the HTML:
<div id="login" style="position:relative; display:none; top:0px; left:0px; right:0px; bottom:0px; text-align:center; vertical-align:middle; z-index:10;" class="trwhole">
<table width="100%" height="100%">
<tr width="100%" height="100%">
<td width="100%" height="100%" style="vertical-align:middle; text-align:center;">
<img src="images/MemorizeItWhite.png" z-index="10000" style="width:290px;">
<table align="center" class="w290">
<tr>
<td>
<div id="lerror" class="alert"></div>
</td>
</tr>
<tr>
<td align="left">Username:
<br>
<input autocorrect="off" autocapitalize="off" type="text" placeholder="username" id="username" style="" class="ui-corner-all w290">
</td>
</tr>
<tr>
<td align="left">Password:
<br>
<input type="password" placeholder="password" id="password" style="" class="ui-corner-all w290" onkeypress="if (event.keyCode==13){login();}">
</td>
</tr>
<tr>
<td>
<input type="button" id="loginBt" onclick="login();" value="Log In" class="submit" style="width:85px;">
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
Here's the selector so far:
$('#login tr:has(input[placeholder]), #signup2 tr:has(input[placeholder])').on("touchstart",
function (evt) { $(evt.target).filter("input").focus(); }
);
Unfortunately
$(evt.target).filter("input").focus();
isn't doing it.
I've also tried
$(this).filter('input').focus();
but the doesn't get focus to the input either.
Any ideas are welcome.
Thanks!
Upvotes: 0
Views: 118
Reputation: 388316
evt.target
refers to the element from where the event is originated, it may not be the tr
element. you can use this
inside the click handler to refer to the tr
element
$('#login tr:has(input[placeholder]), #signup2 tr:has(input[placeholder])').on("touchstart", function (evt) {
$(this).find("input").focus();
evt.stopPropagation();
});
Demo: Fiddle
Upvotes: 1