1

I have a piece of JS that pulls data from the immediate parent of a particular element in a page. The element and its parent are both guaranteed to have certain attributes, so the case is simple. After reading this discussion about the differences between [element].parentElement and [element].parentNode, I get the impression that either one will do the job equally well. But am I right in thinking that parentNode is the better choice? I've read elsewhere that it's older and more DOM-standard. Am I liable to break some users' browsers by a wrong choice between the two alternatives?

Community
  • 1
  • 1
lima
  • 93
  • 1
  • 11
  • Well, apparently FF<9 does not support `parentElement`, while `parentNode` is really supported everywhere. So yes and yes. – Bergi Feb 24 '14 at 20:47
  • While it's not an exact duplicate, it addresses only one unique point of discussion. For that reason I agree it may be better to mark it as a duplicate. – lima Mar 06 '14 at 20:54

1 Answers1

3

Bergi answered this question succinctly. Compliance with DOM standards suggests that parentNode is the preferable term. parentElement is not universally supported and does not introduce enough unique functionality (see the related question for further discussion on that point) to justify its use.

lima
  • 93
  • 1
  • 11