Question

I am using this code to check if the placeholder attribute is supported:

function placeholderIsSupported() {
        var test = document.createElement('input');
        return typeof test.placeholder !== 'undefined';
    }

If the placeholder attribute is supported, I hide the labels in the code here:

//Remove labels, if the placeholder attribute is supported
    if (placeholderIsSupported()) {
        labels = document.getElementsByTagName("label");

        for (i = 0; i < labels.length; i++)
        {
            labels[i].style.display = "none";
        }
    }

However in Opera Mini 7.5 for Android, the labels are hidden, even though the placeholder is not supported. Any ideas how to fix this?

Was it helpful?

Solution

Not sure if it helps, but you could try the following :

'placeholder' in document.createElement('input') && 'placeholder' in document.createElement('textarea');

It's how Modernizr do that check, and it's in most cases quite reliable.

Anyway, I don't think you should reinvent the wheel, there are some polyfills that can do that job for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top