added "parentNode" checking, for node.js usage.