views:

355

answers:

1

I've got a document fragment with children that I want to loop over (when possible). This is causing an error "Cannot read property 'xxx' of null".

How do I test if this will be the case?

+2  A: 

You may want to do the following:

if ((documentFragment !== null) && documentFragment.hasOwnProperty('xxx')) {
    // handle property xxx of documentFragment as required
}
Daniel Vassallo
Matrym
@Matrym: Can you try doing `alert(typeof documentFragment);`. Do you get `object` or `undefined`?
Daniel Vassallo
Uncaught SyntaxError: Unexpected token {
Matrym
@Daniel, it says "Object"
Matrym
@Matrym: Oops... I had a missing/extra parenthesis. Check the updated answer.
Daniel Vassallo