I need to select an element automatically and then quickly focus out of it too.
Here's my HTML:
<div class='input-group date' id='join_date'>
<input type='text' class="form-control dateField" name="join_date" placeholder="MM/DD/YYYY" data-toggle="tooltip" data-placement="top" value="" />
</span>
</div>
I tried putting in focus into the element but don't know how to focus out of it.
unhighlight: function(element, errorClass, validClass)
{
if($(element).hasClass('select2-offscreen'))
{
$(element).closest('.form-group').removeClass('has-error');
$(element).next('span').css({display: "none"});
}
else if($(element).hasClass('dateField'))
{
$(element).select();
//I need to focus out of this element quickly.. there's a reason
}
else
{
$(element).closest('.form-group').removeClass('has-error');
}
},
How can I achieve auto-focusing out of the element? Please help me.
You can use jQuery blur()
function, it will remove the focus out of the focused element.
$("#focus").click(function(){ $("input").focus(); }); $("#blur").click(function(){ $("input").blur(); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='input-group date' id='join_date'> <input type='text' class="form-control dateField" name="join_date" placeholder="MM/DD/YYYY" data-toggle="tooltip" data-placement="top" value="" /> </div> <button id="focus">Focus</button> <button id="blur">Blur (Focus Out)</button>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.