Introduction of the Project: Learn how to create a simple text editor JavaScript application that allows us to edit, capitalize and many other string operations with the user’s input. Let’s see how it’s done.
Method:
- Create buttons to perform operations on text in div.
- Create textarea in div using textarea tag.
- Select elements using document.getElementById method.
- Then change the CSS using JavaScript.
Now let’s get to code!
Â
Create “Index.html” and enter the code given below:-
Text Editor
IAMNK TEXT EDITOR
Copyright © 2022| Powered by I AM NK
Now we are done with the html part. Now it’s time for JavaScript.Â
Create “app.js” and enter the following code given below:-
function f1() {
//function to make the text bold using DOM method
document.getElementById("textarea1").style.fontWeight = "bold";
}
function f2() {
//function to make the text italic using DOM method
document.getElementById("textarea1").style.fontStyle = "italic";
}
function f3() {
//function to make the text alignment left using DOM method
document.getElementById("textarea1").style.textAlign = "left";
}
function f4() {
//function to make the text alignment center using DOM method
document.getElementById("textarea1").style.textAlign = "center";
}
function f5() {
//function to make the text alignment right using DOM method
document.getElementById("textarea1").style.textAlign = "right";
}
function f6() {
//function to make the text in Uppercase using DOM method
document.getElementById("textarea1").style.textTransform = "uppercase";
}
function f7() {
//function to make the text in Lowercase using DOM method
document.getElementById("textarea1").style.textTransform = "lowercase";
}
function f8() {
//function to make the text capitalize using DOM method
document.getElementById("textarea1").style.textTransform = "capitalize";
}
function f9() {
//function to make the text back to normal by removing all the methods applied
//using DOM method
document.getElementById("textarea1").style.fontWeight = "normal";
document.getElementById("textarea1").style.textAlign = "left";
document.getElementById("textarea1").style.fontStyle = "normal";
document.getElementById("textarea1").style.textTransform = "capitalize";
document.getElementById("textarea1").value = " ";
}
Now if we run the Index.html file we will get an output like this:-
Congratulations,
We made a Text Editor Using HTML, CSS, and JavaScript, which I believe is rather cool, and I hope you liked the process as much as I did.
As a result, if you enjoy this, please leave a comment and follow me on YouTube, Facebook, Twitter, and LinkedIn. Don’t forget to subscribe to my channel and clicking the bell icon.