How do I remove the focus of a TextBox in JQuery?
Edit: This is the solution I was looking for:
$(this).trigger('blur');
For an unknown reason, $(this).blur(); did not work. I created a new, clear solution and then it worked.
JS Fiddle
$(function () {
$('input[type=text]').focus(function () {
$(this).val('');
// add the below line to trigger the blur event
$(this).trigger('blur');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="text" value="abcdef">
you can force it to blur using trigger function
$("...").trigger("blur");
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