I need to set focus to "inputOne" input when tabOne is selected, and set focus to "inputTwo" when tabTwo is selected.
<ul class="nav nav-tabs">
<li class="active"><a href="#tabOne" data-toggle="tab">Tab One</a></li>
<li class=""><a href="#tabTwo" data-toggle="tab">Tab Two</a></li>
</ul>
<div id="tabContent" class="tab-content">
<div class="tab-pane fade" id="tabOne">
<input type="text" id="inputOne" />
</div>
<div class="tab-pane fade" id="tabTwo">
<input type="text" id="inputTwo" />
</div>
</div>
Look at this bootply
JS:
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var target = e.target.attributes.href.value;
$(target +' input').focus();
})
You can find doc here :
You can rely on the bootstrap "shown" event for the tabs to handle this:
$(".nav-tabs a").on("shown.bs.tab", function(event) {
$(event.target.href.value + " input").focus();
});
more info on the tab event: http://getbootstrap.com/javascript/#tabs
You can write the following jquery code :
$( "#tabOne" ).click(function() {
$( "#inputOne" ).focusin()
});
Do the same thing for tabTwo
also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With