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

99 views Asked by At

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>`
  );
};
1

There are 1 answers

1
Kannu Mandora On BEST ANSWER

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;
  }