'How to change dynamically 'aria-pressed' = false to true using JS

I have no idea about JS. But there is needed one line of code. i have below JS code.

const quillEditors = document.getElementsByTagName('quill-editor');
      for (let c = 0; c < quillEditors.length; c++) {
        let isDisabledQuillEditor = quillEditors[c].parentElement.getElementsByClassName('ql-disabled')[0];
        if(isDisabledQuillEditor == undefined){
          const buttons = quillEditors[c].parentElement.getElementsByClassName('ql-toolbar')[0].getElementsByTagName('button');
          for (let i = 0; i < buttons.length; i++) {
            if (buttons[i].className == 'ql-bold') {
              buttons[i].setAttribute('aria-label', 'Rich text editor toolbar toggle bold text');
              buttons[i].setAttribute('aria-pressed','false');
              buttons[i].setAttribute('title', 'Bold');
            } else if (buttons[i].className == 'ql-italic') {
              buttons[i].setAttribute('aria-label', 'Toggle italic text');
              buttons[i].setAttribute('aria-pressed','false');
              buttons[i].setAttribute('title', 'Italic');
            }

<quill-editor class="font-caption-alt rich-text-input pd-b-4" maxlength="2000"
                            title="multiline editable description add a new comment required"
                            id="requestJustification" name="requestJustification" pRichTextInput
                            #requestJustification="ngModel" [options]='quillOptions.editOptions'
                            (ready)="quillOptions.accessibleQuill($event)" tabindex="0"
                            (change)="contentChanged($event)"
                            [(ngModel)]="_requestService.requestDetails.RequestJustification"
                            [ngClass]="{'invalid-rich-text-input': (requestJustification.dirty || requestJustification.touched || !isRequestValid || _requestService.requestDetails.isSubmitClicked) && !(_requestService.requestDetails.RequestJustification)}">
                        </quill-editor>

I want JS code to make buttons to make them Pressed=true when user pressed. And need a condition here. What would be the condition.

Please Help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source