First of all, stop using alert to debug! Take a copy of Firebug and FireQuery and use them with console.log() . Even if you work with alert() , you really need to use $("input[type='date']").length to find if the selector returned something - object [object] does not tell you anything useful here.
A higher method for detecting supported input data types is to simply create an input element and skip all available input data types and check if type changing:
var supported = {date: false, number: false, time: false, month: false, week: false}, tester = document.createElement('input'); for(var i in supported){ tester.type = i; if(tester.type === i){ supported[i] = true; } }
This actually exploits the fact that browsers that do not support this type of input return to using text, thereby allowing you to check whether they are supported or not.
Then you can use supported['week'] , for example, to check the availability of the input type week and back up through this. See a simple demonstration of this here: http://www.jsfiddle.net/yijiang/r5Wsa/2/ . You might also consider using Modernizr to more reliably detect HTML5 features.
And finally, the best way to get outerHTML is, believe it or not, use outerHTML . Instead
var inputAttr = $('<div>').append($(this).clone()).remove().html().toLowerCase();
Why not just use:
var inputAttr = this.outerHTML || new XMLSerializer().serializeToString(this);
(Yes, as you can see, there is a caution - outerHTML not supported by Firefox, so we will need a simple workaround from this stack. Overflow question ).
Edit: A testing method was found to support the user interface in the native form from this page: http://miketaylr.com/code/html5-forms-ui-support.html . Browsers that support the user interface for these types in some way should also prevent the entry of invalid values โโin these fields, so the logical extension for the test, which we do above, will be as follows:
var supported = {date: false, number: false, time: false, month: false, week: false}, tester = document.createElement('input'); for(var i in supported){ tester.type = i; tester.value = ':('; if(tester.type === i && tester.value === ''){ supported[i] = true; } }
Again, not 100% reliable - this is only good for types that have certain restrictions on their values, and definitely not very good, but this is a step in the right direction and will certainly solve your problem now.
See the updated demo: http://www.jsfiddle.net/yijiang/r5Wsa/3/