17 February 2023

The Vanilla JS equivalent of jQuery's text() method would be to set the textContent property of a DOM element.

Source code viewer
  1. // Get text content.
  2. const textContent = window.document.querySelector('.my-class-name').textContent;
  3.  
  4. // Set text content.
  5. window.document.querySelector('.my-class-name').textContent = 'Hello, world!';
Programming Language: Javascript