--- title: document.createComment slug: Web/API/Document/createComment tags: - API - DOM - Méthodes - Reference translation_of: Web/API/Document/createComment ---
createComment() crée et retourne un nouveau noeud de type commentaire.
CommentNode = document.createComment(data)
datavar docu = new DOMParser().parseFromString('<xml></xml>', "application/xml");
var comment = docu.createComment('Voici un commentaire pas très bien caché');
docu.getElementsByTagName('xml')[0].appendChild(comment);
alert(new XMLSerializer().serializeToString(docu));
// Affiche: <xml><!--Voici un commentaire pas très bien caché--></xml>