How to enable Heading (h1, h2, h3, h4) on my rich text editor using javascript?

Viewed 404

I am almost done creating a simple text editor. User can write on an Iframe and change text style to bold, italic, etc. But i cant do the same to heading. I would like to know how can I allow users to click on a button and switch from italic/bold to heading (h1, h2, h3, h4, etc).

What I tried so far:

window.addEventListener("load", function (){
var editor = wysiwyg.document;
editor.designMode = "on";

boldButton.addEventListener("click", function (){ editor.execCommand("Bold");}, false)
italicButton.addEventListener("click", function (){ editor.execCommand("Italic");}, false)}, false);

When user clicks the bold btn the text turn bold. How can I implement the same so can user clicks the btn, the text turns to be heading h1 or h2?

1 Answers

i got it.

I just had to use this code

   headingButton.addEventListener("click", function (){ editor.execCommand('formatBlock',false,'h2'); }, false)
Related