I am trying to bold only the text hel
in this fiddle http://jsfiddle.net/yarkpakv/ but it does not seem to be working, what am I doing wrong???
You need to visualize the DOM structure of your A text node that contains only white space. The A text node that has the value So your range must start with the ` element.
range.setStart(root_node, 1);
// End in the `ello` text node, between the two `l`s.
range.setEnd(root_node.childNodes[2], 2);
var newNode = document.createElement("b");
range.surroundContents(newNode);
Here's a fiddle.
element which contains a text node that has the value
h
.ello
. element and ends in the
ello
text node, between the two l
characters. Therefore:var range = document.createRange();
var root_node = document.getElementById("test");
// Start at the `