lundi 1 août 2016

How can i remove the span which created by method document.execCommand()?

the HTML code is

<p contentEditable="true" onmouseup="setColor();">this is some text</p>

and javascript code is

document.execCommand('styleWithCSS', false, true);
document.execCommand('foreColor', false, "rgba(0,0,0,0.5)")

; so the DOM tree becomes:

<p contenteditable="true" onmouseup="setColor();">
    this is <span style="color: rgba(0, 0, 0, 0.498039);">some</span> text
</p>

Noticed that it inserts a span label,with the style attribute,the word's color changed. Now what should i do ,when i want remove the span label?So that the word's color will turn default back.i've tried

document.execCommand('foreColor', false, "");

but it doen't work. Thank you very much!




Aucun commentaire:

Enregistrer un commentaire