--- title: Document.createTextNode() slug: Web/API/Document/createTextNode tags: - API - DOM - Document - Method - Reference - Szöveg - creatTextNode translation_of: Web/API/Document/createTextNode ---
Készít egy új {{domxref("Text")}} node-ot. Ezt a metódust használhatod arra hogy escape-eld a HTML karaktereket a szövegből, mint pl "<" vagy "&"
var textNode = document.createTextNode(text);
<!DOCTYPE html> <html lang="en"> <head> <title>createTextNode example</title> <script> function addTextNode(text) { var newtext = document.createTextNode(text), p1 = document.getElementById("p1"); p1.appendChild(newtext); } </script> </head> <body> <button onclick="addTextNode('IGEN! ');">IGEN!</button> <button onclick="addTextNode('NEM! ');">NEM!</button> <button onclick="addTextNode('ESCAPE <strong>BOLD</strong> AND • ENTITIES! ');">ESCAPE <strong>BOLD</strong> AND • ENTITIES!</button> <hr /> <p id="p1">First line of paragraph.</p> </body> </html>
{{EmbedLiveSample('Example')}}
Specification | Status | Comment |
---|---|---|
{{SpecName('DOM WHATWG', '#dom-document-createtextnode', 'Document: createTextNode')}} | {{Spec2('DOM WHATWG')}} |
{{Compat("api.Document.createTextNode")}}