views:

159

answers:

2
  newNode = document.createElement("span");
  newNode.innerHTML = "text";
  range.insertNode(newNode);

Is it possible to make the text in innerHTML with red background color? I want to add style="background-color:red" to just created span. Is it possible? Or it must have some id, and then I can change this span with jQuery?

+3  A: 

Simple enough:-

newNode.style.backgroundColor = "red";
AnthonyWJones
yes that's it thanks :)
mm
+4  A: 

Better to give a classname for the span

<style>
    .spanClass { background-color: red; }
</style>

newNode.className = "spanClass";
rahul