Remove Focus From Textbox using jQuery
In this tutorial, I will explain how to remove focus from textbox using jQuery. In jQuery, There is a blur property which is used to remove the focus
Description:
In previous articles, I explained How to hide div after some time using jquery, How to change text box background color on focus & blur using jquery, Get Latitude and Longitude from Zip Code using Jquery and many more articles relating to Angular, Node, React & JavaScript . Now I will explain how to use remove focus from textbox using jQuery
To remove focus from textbox we need to write the code like as shown below,
Use The Code:
<script type="text/javascript"> $(document).ready(function () { $('input[type=text]').focus(function () { $(this).val(''); $(this).trigger('blur'); }); }); </script>
If you want to complete code, you need to write the code like as shown below
Use The Code:
<html>
<head>
<title>Remove focus from textbox using jQuery </title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('input[type=text]').focus(function () {
$(this).val('');
$(this).trigger('blur');
});
});
</script>
</head>
<body>
<input type="text" class="form-control" id="txtEmail" value="" placeholder="Enter Email Address" />
</body>
</html>
For your referance Link