How to add empty space characters in a TextArea | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to add empty space characters in a TextArea

When I press the TAB key I would like my text to append four empty spaces from where I selected my text, but my code doesn't seem to work and instead is glitching my TextArea. document.getElementById('code-area').addEventListener('keydown', function(event) { if (event.key == 'Tab') { event.preventDefault(); this.value += ' '; } });

27th Mar 2021, 5:24 PM
Frumkin
Frumkin - avatar
1 Answer
+ 1
tried to call event.preventDefault() at begin?
27th Mar 2021, 5:36 PM
KrOW
KrOW - avatar