cfz
cfz

Reputation: 343

how to set event if cursor is out of an input tag in jquery

im new to jquery and i want to know how to get value of an input tag when a cursor is out/left to that input element/tag. Thank you in advance.

Upvotes: 1

Views: 19775

Answers (3)

thomasbabuj
thomasbabuj

Reputation: 3919

<form>
  <input id="target" type="text" value="Field 1" />
  <input type="text" value="Field 2" />
</form>
<div id="other">
  Trigger the handler
</div>
<script>

$('#target').blur(function() {
  alert('Handler for .blur() called.');
});

Upvotes: 1

Sushanth --
Sushanth --

Reputation: 55750

Use blur event

 $(function() {
    $('input[type="text"]').on('blur' , function() {
        // Your code here
    });
  });

CHECK DEMO

Upvotes: 13

juan.obando
juan.obando

Reputation: 209

I think the method you're searching is focusout

$(function() {
    $('#input-element').focusout(function() {
        // put your code here!
    });
});

I hope it helps.

Upvotes: 5

Related Questions