Reputation: 237
I was trying to figure out how to make a style editor for html. Like you can use here on stackoverflow the bold function. You can make text bold with the javascript function
str.bold();
This will bold the string you put in of course. I want to make it so when you click on a button the next things you type will be bold. When you click on it again the next thing you type will not be bold again.
I thought of some things. But all of them were not really possible.
Upvotes: 0
Views: 125
Reputation: 4896
Actually it can be easily implemented with an editable div
and document.execCommand('bold')
. You will have additional functionality like using keyboard shortcut (ie. ctrl+B), highlight and bold..
#text {
width : 500px;
min-height : 100px;
border : 2px solid;
}
<div id="text" contenteditable="true"></div>
<button id="toggle_bolt" onclick="document.execCommand('bold');">toggle bolt</button>
Upvotes: 1