Reputation: 305
I am creating a effect using focus
function in jQuery. On input focus a div is move down from top where the user can fill the data here is the jsfiddle example of that thing what i want now problem is it is working fine for first time the div is move down properly but when i click on that input again it is not working that time. i also used blur effect to focus out from input but after that i am not able to click on input box again. So i want to know how it'll work on second time.
Here is my jQuery code and rest is in example
$( document ).ready(function() {
$( "#getcoupon" ).focus(function(){
$("#toggle").attr('checked', true);
$(document).keyup(function(e) {
if (e.keyCode == 27) {
$("#toggle").attr('checked', false);
// $("#getcoupon").focus();
}
});
});
});
Upvotes: 0
Views: 914
Reputation: 3261
I have simplified your code like this:
$( document ).ready(function() {
$( "#getcoupon").focus(function(){
$("#toggle").prop('checked', true);
});
$(document).keyup(function(e) {
if (e.keyCode == 27) {
$("#toggle").prop('checked', false);
$( "#getcoupon" ).blur();
// $("#getcoupon").focus();
}
});
});
Upvotes: 0