Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6981049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:06:22+00:00 2026-05-27T18:06:22+00:00

Is there a freely available jQuery plugin that changes placeholder behavior to match HTML5

  • 0

Is there a freely available jQuery plugin that changes placeholder behavior to match HTML5 spec?

Before Focus
chrome unfocused placeholder

On Focus Good (Safari)
safari focused placeholder

On Focus Bad (Chrome, Firefox)
chrome focused placeholder

You can what your browser does with this simple fiddle.

HTML5 draft spec says:

User agents should present this hint to the user, after having stripped line breaks from it, when the element’s value is the empty string and/or the control is not focused (e.g. by displaying it inside a blank unfocused control and hiding it otherwise).

The “/or” is new in current draft so I suppose that’s why Chrome and Firefox don’t support it yet. See WebKit bug #73629, Chromium bug #103025.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:06:23+00:00Added an answer on May 27, 2026 at 6:06 pm

    Stefano labels

    Stefano J. Attardi wrote a nice jQuery plugin that just does that.
    It is more stable than Robert’s and also fades to a lighter grey when the field gets focused.

    • See the demo page
    • Grab it on GitHub
    • Play with the fiddle

    I modified his plugin to read placeholder attribute as opposed to manually creating a span.
    This fiddle has complete code:

    HTML

    <input type="text" placeholder="Hello, world!">
    

    JS

    // Original code by Stefano J. Attardi, MIT license
    
    (function($) {
        function toggleLabel() {
            var input = $(this);
    
            if (!input.parent().hasClass('placeholder')) {
                var label = $('<label>').addClass('placeholder');
                input.wrap(label);
    
                var span = $('<span>');
                span.text(input.attr('placeholder'))
                input.removeAttr('placeholder');
                span.insertBefore(input);
            }
    
            setTimeout(function() {
                var def = input.attr('title');
                if (!input.val() || (input.val() == def)) {
                    input.prev('span').css('visibility', '');
                    if (def) {
                        var dummy = $('<label></label>').text(def).css('visibility','hidden').appendTo('body');
                        input.prev('span').css('margin-left', dummy.width() + 3 + 'px');
                        dummy.remove();
                    }
                } else {
                    input.prev('span').css('visibility', 'hidden');
                }
            }, 0);
        };
    
        function resetField() {
            var def = $(this).attr('title');
            if (!$(this).val() || ($(this).val() == def)) {
                $(this).val(def);
                $(this).prev('span').css('visibility', '');
            }
        };
    
        var fields = $('input, textarea');
    
        fields.live('mouseup', toggleLabel); // needed for IE reset icon [X]
        fields.live('keydown', toggleLabel);
        fields.live('paste', toggleLabel);
        fields.live('focusin', function() {
            $(this).prev('span').css('color', '#ccc');
        });
        fields.live('focusout', function() {
            $(this).prev('span').css('color', '#999');
        });
    
        $(function() {
           $('input[placeholder], textarea[placeholder]').each(
               function() { toggleLabel.call(this); }
           );
        });
    
    })(jQuery);
    

    CSS

    .placeholder {
      background: white;
      float: left;
      clear: both;
    }
    .placeholder span {
      position: absolute;
      padding: 5px;
      margin-left: 3px;
      color: #999;
    }
    .placeholder input, .placeholder textarea {
      position: relative;
      margin: 0;
      border-width: 1px;
      padding: 6px;
      background: transparent;
      font: inherit;
    }
    
    /* Hack to remove Safari's extra padding. Remove if you don't care about pixel-perfection. */
    @media screen and (-webkit-min-device-pixel-ratio:0) {
        .placeholder input, .placeholder textarea { padding: 4px; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a freely available GUI tool that will allow interaction with Microsoft SQL
Is there either: A freely available program that can convert the output of a
Is there any freely available library (other than java media framework) that I can
Is there any Tree-Grid component that is freely available for a C# project? A
Is there any Diagramming component that is freely available for a C# project? If
Is there a freely available library to create a MPEG (or any other simple
Is there a freely available Base64 decoding code snippet in C++?
When thinking about iPhone/iPad applications security, I can notice that there is: Widely available
I want to parse SQL code using C#. Specifically, is there any freely available
Is there some place of freely available themes/skins for standard Django apps? I mean

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.