I'm creating a simple word processor where the user can enter any text in the dedicated text area and press three buttons which will make the text bold, italic and underline it. I've managed to do this so far however it has to undo the changes if the button has been clicked again.
I can't seem to unbold the text even when I insert both functions inside onclick.
<script>
function myFunctionBold() {
document.getElementById("demo").style.fontWeight = "bold";
}
function myFunctionUnBold() {
document.getElementById("demo").style.fontWeight = "normal";
}
function myFunctionItalic() {
document.getElementById("demo").style.fontStyle = "italic";
}
function myFunctionUnderline() {
document.getElementById("demo").style.textDecoration = "underline";
}
</script>
<style>
.buttonsBold {
height: 21px;
cursor: pointer;
display:inline-block;
margin: 5px 4px;
font-weight: bolder;
}
.buttonsItalic {
height: 21px;
cursor: pointer;
display:inline-block;
margin: 5px 4px;
font-style: italic;
}
.buttonsUnderline {
height: 21px;
cursor: pointer;
display:inline-block;
margin: 5px 4px;
text-decoration: underline;
}
</style>
<body>
<p>This is a simple word processor.<br>
Type some text in the text area and press the buttons!
</p>
<form action="textarea">
Enter text here:<br>
<input id="demo" type="text" name="yourText">
</form>
<br>
<button class="buttonsBold" onclick="myFunctionBold(); myFunctionUnBold();" >Bold</p>
<button class="buttonsItalic" onclick="myFunctionItalic()">Italic</p>
<button class="buttonsUnderline" onclick="myFunctionUnderline()">Underline</p>
</body>
</html>