Web developer How to make button to delete letter in this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Web developer How to make button to delete letter in this code?

In this code when I click on any button a letter is write in text area how to make button to delete this letter? https://code.sololearn.com/WTULRuz9d6Me/?ref=app

26th Apr 2017, 1:34 PM
Kirollos Ayman
8 Answers
+ 15
Maybe the problem is the name of function, the code of @Ashwani works well with me, in short... you have to replace the name of function, @Ashwani has setted the name in "deleteChar()", you have to set the name in "text()" and replace your text() function. As @Abdel said, his code reset the text and doesn't work for delete a single character, use the function of @Ashwani but change the name of the function. Bye.
26th Apr 2017, 2:18 PM
Maz
Maz - avatar
+ 9
You can use below function on click of delete button. function deleteChar(){ var text = document.getElementById("my") .innerHTML.toString(); document.getElementById("my") .innerHTML = text.slice(0, text.length-1); }
26th Apr 2017, 1:42 PM
Ashwani Kumar
Ashwani Kumar - avatar
+ 8
If you want character by character deletion of the present text in the text area, then this is the code and works fine. If your requirement is something else, then you can explain further.
26th Apr 2017, 2:03 PM
Ashwani Kumar
Ashwani Kumar - avatar
+ 5
I try it but it is wrong
26th Apr 2017, 1:59 PM
Kirollos Ayman
+ 5
Yeah , when I used @Ashwani code I changed the function name to text() as @Maz said tip: @Kirollos Ayman your javascript didn't went alright, don't forget to look at the console GOOD LUCK
26th Apr 2017, 2:24 PM
Abdel
Abdel - avatar
+ 5
thanks very much for your answer
26th Apr 2017, 2:35 PM
Kirollos Ayman
+ 4
Hey @Kirollos I have edited the last function and the last button It works. but the above code from @Askhwani is the best because mine resets everything and that's not cool GOOD LUCK function text(){ document.getElementById("my").innerHTML = ''; } <button onclick="text()">Delete</button>
26th Apr 2017, 2:09 PM
Abdel
Abdel - avatar
+ 2
which one @Kirollos ?
26th Apr 2017, 2:15 PM
Abdel
Abdel - avatar