/ Published in: jQuery
Couple of ways to check if HTML5 form elements exist and use a fallback if they don't.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// don't forget this <script src="/jq/jquery.validate.js"></script> <script> jQuery(function() { if (!checkAttribute('input', 'required')) { // check for html5 validation jQuery("#form").validate(); // no? hey, use jQuery validate } if (!checkAttribute('input', 'autofocus')) { // check for html5 validation document.getElementById("q").focus(); // no? hey, use jQuery focus() } }); function checkAttribute(element, attribute) { //the function var test = document.createElement(element); if (attribute in test) { return true; } else { return false; } } </script>
URL: http://diveintohtml5.org/forms.html