Placeholder text

Isn't it nice when you visit a site, and there's some soft grayed-out text in a form field giving you a hint about what you're supposed to put there? There are umpteen different jQuery plugins that have been written over the past several years to handle this because it can be a bit of a hassle.

However, I'm here with good news. HTML5 provides a placeholder attribute that can be used to create this kind of text in form fields automatically without any help from JavaScript. Of course, as with any other cutting-edge technology, browser support can be a bit lacking. We don't have the luxury of waiting years for browser support for this new feature to be universal—we have to build functioning websites now. You could continue using all those old jQuery plugins, but why not take advantage of support for the placeholder attribute if it's there and only use jQuery to fill in the gaps for those browsers that don't recognize it yet?

This type of script is called a polyfill. It's used to fill in functionality that might be missing from some browsers. If a browser does support the placeholder attribute, the polyfill script does nothing, and just lets the browser handle the placeholders. For all those site visitors without support for the placeholder attribute, the script springs into action, providing the placeholder text functionality for everyone.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.220.114