randomKek
randomKek

Reputation: 1128

jquery live focus blur

How can I do a blur and focus method in jQuery "on" method, focus is working perfect, blur isn't how can I do this?

I have tried:

$(document).on('focus', '.activityLikeButton', function(){
    // works
});

$(document).on('blur', '.activityLikeButton', function(){
    // does not work
});

as the comments say, the focus is working perfect, the blur isn't.

Thanks for your time.

Upvotes: 2

Views: 1290

Answers (1)

gentrobot
gentrobot

Reputation: 671

I tried with alerts and it didn't work. However, when I set a value for the textbox, on which I am using the focus and blur, it worked for me too.

<script>
$(document).ready(function(){
  $(document).on('focus', '.box', function(){
    $(this).val('hgfvs');
   });

   $(document).on('blur', '.box', function(){
    $(this).val('');
   });

});
</script>
</head>
<body>
<input type="text" class="box" />

Upvotes: 3

Related Questions