Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modernizr just for one quick check?

I want to check if the browser who's running my page is capable of handling the 'html 5 placeholder'

I know I can add the following javascript check:

!Modernizr.input.placeholder

but is it worth to import a library just for one check ?

also how does modernizr do that for me (i mean how is it implemented under the cover) ?

like image 304
Zo72 Avatar asked Nov 04 '11 13:11

Zo72


2 Answers

If you want to check for placeholder support, then all you need to do is;

var placeholderSupport = "placeholder" in document.createElement("input");

And to answer your other question; no, there is absolutely no point including the whole Modernizr library for 1 line of JS (Modernizr is 1000+ lines.... go figure :))*

*Yes, not minified, but the concept remains

like image 136
Matt Avatar answered Oct 18 '22 05:10

Matt


You could just get what you need from modernizr by just selecting "Input Attributes" for example and generate a build

http://www.modernizr.com/download/

like image 39
Marty Avatar answered Oct 18 '22 03:10

Marty