Input without label (like a placeholder)

    * Code by Marcio Toledo

    // This is like placeholder of HTML5
    // Inicio a variavel que representa o value dos campos que funcionam como label
    var input_value;
    // Ativando os campos
    $(‘.label’).focus(function () {
    input_value = $(this).val();
    }).blur(function() {
    if (this.value == ”) {


    One Reply to Input without label (like a placeholder)

    1. Willy says:

      input_value = $(this).val();

      This is 3 calls to the same “this” element, who goes through the DOM to find it each time.
      This is a ressource consumer on large apps.

      Try this piece of code instead :
      var $this = $(this); // Only one call
      var input_value = $this.val(); // Element is cached
      $this.val(”).addClass(‘active’); // Don’t forget to chain

    Leave a Reply