Detecting HTML5’s Placeholder

Update: jQuery Plugin

HTML5 WG has implemented an input or textarea attribute feature named “placeholder.” It acts similar to suggestive pre-populated input text that clears on element focus.

While developing jQuery’s Simple Clearfield I discovered a way to test for the browser’s support of the placeholder attribute. Here’s the code:

function placeholder_support (){

var i = document.createElement('input');

return 'placeholder' in i; // returns true if supported

}
blog comments powered by Disqus