Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
How to grab textarea element from event without jQuery

I am trying to get the value of the textarea element in my form using plain JavaScript events. I am using Vue.js (I am not using v-model as the form will be dynamically generated so there could be more than 1 for example). I have tried a few different approaches. I can seem to grab everything other than the textarea element

console.log(event.target.closest("textarea"));
console.log(event.target.parentNode.closest("textarea"));
console.log(event.target.parentNode.closest("form textarea"));
console.log(event.target.parentNode.closest("form > textarea"));
console.log(event.target.parentNode.closest("textarea > form"));
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

.closest() searches for the closest parent element, not a child element. Use that to find the enclosing form.

Then use .querySelector() to search for a descendant element starting from there.

console.log(event.target.closest("form").querySelector("textarea").value);
about 4 years ago · Juan Pablo Isaza Report

0

If you're using a form to submit the values, you can make use of the FormData object to parse all inputs:

const formElement = document.getElementById('form');

formElement.addEventListener('submit', (event) => {
  event.preventDefault();
 
  const formData = new FormData(event.target);
  
  console.log(formData.get('textValue'));
});
<form id="form">
  <textarea name="textValue">Lorem ipsum dolor</textarea>
  <br />
  <input type="submit" value="Submit" />
</form>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!