Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

78
Views
How to capitalize first letter of textarea HTML?

I am a newbie in web programming and I am looking for a way to capitalize just the first letter of a textarea. I've already tried this solution found on the web but it doesn't work.

<p class="textarea_part">
    <textarea name="#" placeholder="La tua richiesta"></textarea>
</p>

<style>
    .textarea_part::first-letter {
         text-transform: capitalize;
     }
</style>

How can I solve this problem?

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

Using javascript:

document.querySelector('.textarea_text').addEventListener('input', () => {
  text = document.querySelector('.textarea_text').value;
  document.querySelector('.textarea_text').value = text.charAt(0).toUpperCase() + text.slice(1);
})
<p class="textarea_part">
    <textarea name="#" placeholder="La tua richiesta" class="textarea_text"></textarea>
</p>

Thanks, @marcus-parsons for informing me of the input event listener! It's much faster for the javascript method now.

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs