I want to use the HTML5
"placeholder"
attribute in my code if the user's browser supports it otherwise just print the field name on top of the form. But I only want to check whether placeholder is supported and not what version/name of browser the user is using.
So Ideally i would want to do something like
<body> <script> if (placeholderIsNotSupported) { <b>Username</b>; } </script> <input type = "text" placeholder ="Username"> </body>
Except Im not sure of the javascript bit. Help is appreciated!
A variable is a placeholder for an unknown quantity.
The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample value or a short description of the expected format). The short hint is displayed in the input field before the user enters a value.
The :placeholder-shown pseudo-class selects the input element itself when placeholder text exists in a form input. Think of it as a nice way to distinguish between inputs that are currently showing placeholder text versus those that are not.
Definition and Usage The placeholder attribute specifies a short hint that describes the expected value of a input field / textarea. The short hint is displayed in the field before the user enters a value.
function placeholderIsSupported() { var test = document.createElement('input'); return ('placeholder' in test); }
I used a jQuery-ized version as a starting point. (Just giving credit where it's due.)
Or just:
if (document.createElement("input").placeholder == undefined) { // Placeholder is not supported }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With