document.createComment
createComment()
crée et retourne un nouveau noeud de type commentaire.
Syntaxe
CommentNode = document.createComment(data)
Paramètres
data
-
Une chaîne de caractères représentant le contenu du commentaire.
Exemple
var 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>