I went ahead and made a JSPerf for comparing the selectors input[placeholder]
, .hasPlaceholder
and input
with a .filter()
.
Now that we have some numbers to think about, lets talk about why you want to know.
When are you doing this search for 'input[placeholder]'
? Hopefully only once. If you do either of these selectors in a modern browser, they will be pretty speedy (the number is operations per second....). However if you know you are only running this selectors on browsers that don't support placeholders, of the three methods listed, the .hasPlacehoder
is actually the slowest in IE 6, with the custom filter winning. You want to try testing performance in the browsers that this code will actually affect..
Feel free to add your own selectors, or even better closer to your exact HTML to that page and solicit some browser testing!
Edit: I added input.hasPlaceholder
to the race on a new perf...