This is a newb question, but it makes me pulling my hairs:
<div class="search-input-field">
<input type="text" value="amazon" placeholder="Search" name="search" id="search">
</div>
I would like to get the value of this input when user mouseOut. How can I do this using jQuery/javaScript?
Thank you.
You can use
.val()to get the value of a form element:You can also use
.attr()to get an attribute for an element:Docs:
.val(): http://api.jquery.com/val.attr(): http://api.jquery.com/attrAn example of your desired code:
Notice that you can get the value of an input element inside an event handler with
this.valuewhich will perform much faster than using$(this).val().[Suggestion] – If you want to get the value after the user has finished editing the value of the input then I suggest using the
blurevent (mouseoutfires when the user moves the cursor over the element, then away):Note that
.on()is new in jQuery 1.7 and in this case is the same as using.bind().