-
Couldn't load subscription status.
- Fork 0
ProtoString toNode() Method
Seth Clydesdale edited this page May 23, 2015
·
3 revisions
The text can be converted and appended to an element as much as you want, if the node is not assigned to a variable.
var str = 'I\'m going to be innerHTML one day !';
/*** The content of str is set as the innerHTML content ***/
document.body.appendChild(str.toNode()); // appends a P node to the body
document.body.appendChild(str.toNode('STRONG')); // appends a STRONG node to the bodyWhat's returned in the process is a DOM Node, so you can use all methods of the Node object when assigned to a variable. Note however, that you cannot append the node more than once this way.
var str = 'I\'m STRONG and nobody can beat me !'.toNode('STRONG');
str.id = 'theStrongElementThatCould';
str.style.color = 'red';
document.body.appendChild(str);The toNode method converts a text string into a DOM Node, with the text set as the innerHTML content. The method can be used to quickly apply a text string to a Node for addition to the DOM.
String.toNode(tag);| Parameter | Description |
|---|---|
| tag | A string which determines the HTML element that the string will be converted into. The value of the string should be the tag name of the element, such as P, STRONG, A, etc.. The String is converted to a P element by default if left undefined. |
Home • History • ProtoString • Created by Seth Clydesdale