Search code examples
javascriptreactjsej2-syncfusion

Property 'innerText' does not exist on type 'HTMLCollectionOf<Element>'


I am trying to excess the html element and want to replace the inner content:- Here is the code i am trying:-

import { RichTextEditorComponent } from "@syncfusion/ej2-react-richtexteditor";

export const handleSignatureSelect = (
  signature: string,
  editorRef: React.RefObject<RichTextEditorComponent>
) => {
  const currentSignature = document.getElementsByClassName("gmail_signature");
  if (currentSignature) {
    currentSignature.innerText = signature;
    return;
  }

  editorRef.current?.executeCommand(
    "insertHTML",
    `<br><br clear="all"><div><br></div><br><div dir="ltr" class="gmail_signature" 
     data-smartmail="gmail_signature">${signature}</div>`
  );
};

Solution

  • You code should be like this because after using getElementByClassName it return an array.

      const currentSignature = document.getElementsByClassName("gmail_signature")[0];
      if (currentSignature) {
        currentSignature.innerText = signature;
        return;
      }