Best way to check if browser supports `.textContent`?
browser-feature-detection, dom, javascript, performance
Solution
With...
'textContent' in document.body
... expression you'll just check a property (textContent) existence in `document.body` object, without actually checking its value.
And yes, it is `false` in IE8.
Problem
I want to check if the browser supports `.textContent` I have thought these options: - `if( document.body.textContent ) { }` - `if( document.createElement('div').textContent !== void(0) ) { }` Of course, the first one is simpler, but the problem I see is that maybe the browser calculates all the string, which can be slow if the website is huge. Then, which one should I choose? Or is there a better option? Edit: I have created a jsperf