onfocusout event in Jquery

This event triggers when you focus on an element and then click anywhere else outside of that element. This works for input fields or any other element that has a contenteditable:true attribute.

Example~

<!DOCTYPE html>
<html>
<head>
  <title>Jquery on focusout event</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>



<h1 contenteditable="true" align="center">Click me and then click anywhere else.</h1>

<script>
 $(document).ready(function(){
   $("h1").on("focusout",function(){
      alert();
   });
});
</script>
</body>
</html>

Leave a Comment