I would like to focus the <input>
element.
<div id="table_filter" >
<label>Suche:
<input type="search" placeholder="Suchbegriff(e)" >
</label>
</div>
I tried:
$("#table_filter").children().children()[0].focus;
CodePudding user response:
focus
in jQuery
is a method. You have to select the target using your selector and call focus
using focus()
.
You can also use these selectors to select your target
$("#table_filter input[type='search']")
OR
$("#table_filter input.form-control.form-control-sm")
Working Fiddle
<script>
$(document).ready(function () {
$("#table_filter").children().children()[0].focus();
// $("#table_filter input[type='search']").focus();
// $("#table_filter input.form-control.form-control-sm").focus();
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div id="table_filter" >
<label>Suche:
<input type="search" placeholder="Suchbegriff(e)">
</label>
</div>