HTML5 is not exactly a feature that you can check whether or not it is present. HTML5 was the name given to a series of methods, components, and tags added to the HTML language that were gradually being supported by browsers.
Something I think it’s important to mention is that all major browsers accept HTML5 Features and have been doing it for a long time so I don’t quite understand why you want to do this check instead of simply assuming that the browser has the validation and ready. Let the old browsers die.
Another topic worth mentioning is: One should not rely on any validation just at the front-end, are simple to circumvent even by inspectors.
With that said, you and knowing that HTML5 is not something you can check whether it is there or not, what you can do is directly check the method you need.
In the case of validation, you can select a form on your page document.querySelector('form')
access the __proto__
(where all native methods of that element are located and check whether the method checkValidity
(which is the name of the method that validates HTML) exists or not.
if (typeof document.querySelector('form').__proto__.checkValidity) === 'function' {
// O formulário tem validação nativa
} else {
// O formulário não tem validação nativa
}
https://caniuse.com/#search=required
– LeAndrade
Leai aqui: https://answall.com/questions/30504/tem-comofazer-feature-detection-pra-css e aqui tb https://answall.com/questions/316656/o-que-s%C3%A3o-Feature-queries-no-css-como-se-o-uso-delas-para-que-que-servir
– hugocsl
to you can try to use the modernizr
– Eduardo
Carlos, I didn’t understand why the question took several negatives, so I tried to edit it to clarify the problem better. See if I didn’t end up changing something important from the original question.
– Woss