Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
46
rated 0 times [  49] [ 3]  / answers: 1 / hits: 24102  / 13 Years ago, fri, november 25, 2011, 12:00:00

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!


More From » html

 Answers
16
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.)


[#88914] Wednesday, November 23, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sandra

Total Points: 708
Total Questions: 100
Total Answers: 84

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
sandra questions
Tue, Jun 30, 20, 00:00, 4 Years ago
Sun, May 31, 20, 00:00, 4 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Fri, May 31, 19, 00:00, 5 Years ago
;