"wrong_focus"
Bootstrap 3.3.0 Snippet by daman

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <h2>On button click focus Text Field</h2> <form> <div class="form-group"> <input type="text" id="parent1" class="inputField" /> <button type="button" class="btn btn-primary triggerBtn">Focus me!</button> </div> <div class="form-group"> <input type="text" id="parent2" class="inputField"/> <button type="button" class="btn btn-primary triggerBtn">Focus me!</button> </div> <div class="form-group"> <input type="text" id="parent3" class="inputField" /> <button type="button" class="btn btn-primary triggerBtn">Focus me!</button> </div> <div class="form-group"> <button type="button" id="child1" class="btn btn-success">Enter 1</button> <button type="button" id="child2" class="btn btn-success">Enter 2</button> <button type="button" id="child3" class="btn btn-success">Enter 3</button> </div> </form> </div>
$(document).on("click",".triggerBtn", function() { var TextField = $(this).closest('div').find('.inputField').focus(); if($(TextField).is(":visible")) { $(TextField).focus(); } $('#child1').click(function(){ $(TextField).val("1"); }); $('#child2').click(function(){ $(TextField).val("2"); }); $('#child3').click(function(){ $(TextField).val("3"); }); });

Related: See More


Questions / Comments: