How to change the shape of a textarea using JavaScript?
In General, Textarea will be in the form of rectangular or square shapes, but here we will deal with Unusual shapes of textarea which means this textarea will not be regular shapes but editable.
- Method 1:
In the first method, let’s see the irregular editable textarea created using CSS-shapes and content editable attribute when it is true.Program 1:
<!DOCTYPE html><html><head><style>div {top: 124px;margin-left: 150px;outline: none;}#parallelogram {color: white;font-weight: bold;width: 250px;height: 200px;transform: skew(20deg);background: #f00;overflow: hidden;}#eq-triangle {width: 300px;height: 0;border-bottom: 104px solid blue;/* 104 = 120 * 0.866 */border-left: 60px solid transparent;border-right: 60px solid transparent;}.circle {display: table-cell;padding: 40px;width: 200px;height: 200px;border-radius: 50%;font-size: 30px;color: #fff;line-height: 50px;text-align: center;background: #40a977;word-break: break-all;justify-content: center;overflow: hidden;}</style></head><body><h1>Parallelogram Shaped TextArea</h1><label><h3>Enter Comments:</h3></label><divid="parallelogram"contenteditable="true">Enter the something...</div><h1>eq-triangle shaped TextArea</h1><label><h3>Enter Comments:</h3></label><divid="eq-triangle"contenteditable="true">Enter the something...</div><h1>Circle shaped TextArea</h1><label><h3>Enter Comments:</h3></label><divclass="circle"contenteditable="true">Enter the something...</div></body></html>chevron_rightfilter_noneOutput:

- Method 2:
Change the shape of textarea using JavaScript. First get the element using id and then change the shape using style.transform = “skew(40deg)”;.Program 2: Lets use javascript to create unusual textarea.
<!DOCTYPE html><html><head><style>textarea {color: brown;font-weight: bold;width: 250px;height: 200px;background: #ff7;overflow: hidden;}</style></head><body><center><h1style="color:green">GeeksforGeeks</h1><textareaid="myP">Unusual shape of a textarea</textarea><br><buttononclick="myFunction()">Try it</button><pid="demo"></p><script>function myFunction() {var x = document.getElementById("myP").style.transform = "skew(40deg)";document.getElementById("demo").innerHTML = x;}</script></center></body></html>chevron_rightfilter_noneOutput:
Before:

After:

Recommended Posts:
- How to change the Content of a <textarea> using JavaScript ?
- How to disable arrow key in textarea using JavaScript ?
- How to set textarea scroll bar to bottom as a default using JavaScript/jQuery ?
- How to create auto-resize textarea using JavaScript/jQuery ?
- How to change the text of a label using JavaScript ?
- Change an element class JavaScript
- How to dynamically change the title of web page using JavaScript ?
- How to change the src attribute of an img element in JavaScript / jQuery ?
- JavaScript | Change the text of a span element
- How to change the background color after clicking the button in JavaScript ?
- How to change cursor to waiting state in JavaScript/jQuery ?
- How to change style attribute of an element dynamically using JavaScript ?
- How to change the value of a global variable inside of a function using JavaScript ?
- How to disable scroll to change number in <input type="number"> field using JavaScript/jQuery?
- How to change text color depending on background color using JavaScript?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



