0

I need to animate a div when focus an input. I tried this but is not working.

$("input").focus(function() {
    $("div").animate({
        marginLeft: "0"
    }, 500);
});

The initial position is margin-left: -500px. The jQuery is installed correctly. When I try to do the same but with a div instead of a input It works.

$(".a_div").click(function() {
$("div").animate({
    marginLeft: "0"
}, 500);
});

But I changed to an input and no longer works.

  • `I tried this but is not working.` what do you mean by not working can you create a snippet for demo? – guradio Jul 26 '16 at 02:11
  • What is the `
    `'s value for `margin-left` before the animation? Also, is jQuery installed correctly?
    – Jonathan Lam Jul 26 '16 at 02:12
  • The initial position is margin-left: -500px. And yes, jQuery is installed correctly. When I try to do the same but with a div instead of a input It works. $("input").click(function() { $("div").animate({ marginLeft: "0" }, 500); }); But I changed to an input and no longer works. –  Jul 26 '16 at 02:25
  • Here is fiddle. https://jsfiddle.net/Harin/mnjdn3cx/1/ . Working fine. – Harish Kommuri Jul 26 '16 at 02:33
  • check out this it works on focus in : https://jsfiddle.net/3338cej0/ – Sunil Kumar Jul 26 '16 at 02:48
  • Look a example event input http://stackoverflow.com/a/43665925/2777092 – KingRider Apr 27 '17 at 19:03

0 Answers0