TreeWalker.firstChild()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

La méthode TreeWalker.firstChild() déplace le Node courant vers le premier enfant visible du noeud courant et renvoie l'enfant trouvé. Il déplace aussi le noeud courant vers cet enfant. Si aucun enfant n'existe, elle renvoie null et le noeud courant n'est pas modifié.

Syntaxe

js
node = treeWalker.firstChild;

Exemple

js
var treeWalker = document.createTreeWalker(
  document.body,
  NodeFilter.SHOW_ELEMENT,
  {
    acceptNode: function (node) {
      return NodeFilter.FILTER_ACCEPT;
    },
  },
  false,
);
var node = treeWalker.firstChild(); // renvoie le premier enfant de l'élément racine ou null si aucun

Spécifications

Specification
DOM
# dom-treewalker-firstchild

Compatibilité des navigateurs

Voir aussi

  • L'interface TreeWalker à laquelle elle appartient.