Reputation: 1309
Hi all i am working on jquery i have a text area i need to select class for hide functions in jquery once it load it will be displayed when i eneter and when i leave it should hide
here my code follows:
<script type="text/javascript">
$(document).ready(function () {
$('.select').mouseleave(function () {
$('.select').hide();
});
});
</script>
here my html:
<textarea rows="10" class="select" id="editor1"> </textarea>
here i have my textarea right i need when entered no function will be fired when i leave the textarea it shouls hide for that i need to call text area with class so i need to how to fine a textarea class any help wil be appreaiated thanks
Upvotes: 1
Views: 2341
Reputation: 106
You almost have it right; although mouseleave is when the mouse hovers over it then leaves (hence the event name).
For text input you're better of using focusout; example below.
<script>
$(document).ready(function () {
$('.select').on("focusout",function () {
$(this).hide();
});
});
</script>
Upvotes: 0
Reputation: 22570
$('.select').mouseleave(function () {
$(this).hide();
});
Altho you might wanna try:
$('.select').blur(function () {
$(this).hide();
});
And as per your question in title
$('.select') /* This will select every single element
that has the class "select" */
Whereas
$('#editor1') /* This will select ONLY the first
element that has the id "editor1" */
And inside any event or func call on an element, $(this) represents the element called:
$(".select").blur(function(e) {
$(this) // represents the current element losing focus
});
Upvotes: 4