Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery detect if input is filled

I created this function which animates label when input has focus.

$("input").on("focus", function () {
  $(this).siblings().animate({
    top: "-20",
  }, 70, function() {
  });
});

I would like animate it back if input stays unfilled.

Here is my codepen

like image 989
Karolina Ticha Avatar asked Apr 09 '26 03:04

Karolina Ticha


1 Answers

$("input").on("focus", function () {
  $(this).siblings().animate({
    top: "-20",
  }, 70, function() {
  });
});

$("input").on("blur", function() {
  if( $(this).val().length == 0 ) {
    $(this).siblings().animate( {
      top : "0"
    });
  }
});

http://codepen.io/anon/pen/VavgLv

like image 153
Praveen Avatar answered Apr 11 '26 17:04

Praveen