tags:

views:

126

answers:

1

I want to use isElementContentWhitespace on text nodes,
but not all browsers support it, so I need to check if its supported,
then if is, use it, if not implement jquery's $.trim...

i've tried doing something like this with no luck on IE, good on FF:

var testEl = document.createElement('span');  
testEl.innerHTML = ' ';  
alert( testEl.firstChild.isElementContentWhitespace );
+3  A: 

ok, I've managed to test for this prop!

var testEl = document.createTextNode('text');  
alert('isElementContentWhitespace' in testEl);

works great in IE also... :)

vsync
Yep, this is it. Don't expect all the whitespace nodes in the document to be `isElementContentWhitespace` though, it only applies when the parent Element is defined as containing only other elements, not MIXED content. So eg. a whitespace-only TextNode inside `<div>` will never set `isElementContentWhitespace` true. The MDC page's description of the property is a little misleading.
bobince
well, this is certainly a bummer. its super important what you just said, but I never have read it nowhere. good to have these things written here.
vsync