Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript document.execCommand() own tags

I've found some really interesting! The execCommand function applies many useful features. But is it possible to work with OWN wraps? Like:

document.execCommand("styleWithCSS", false, "<span class='own-class'>");

Everything related i've found was pretty old… so maybe one of you knows a good workaround or something.

like image 354
YeppThat'sMe Avatar asked May 13 '13 19:05

YeppThat'sMe


1 Answers

Thanks to dandavis.

The following works very well:

document.execCommand("insertHTML", false, "<span class='own-class'>"+ document.getSelection()+"</span>");
like image 93
YeppThat'sMe Avatar answered Oct 18 '22 13:10

YeppThat'sMe