# ForEach and rich text editor

**URL:** <https://forum.freecodecamp.org/t/foreach-and-rich-text-editor/228202>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [September 19, 2018, 3:21pm UTC](https://forum.freecodecamp.org/t/foreach-and-rich-text-editor/228202 "2018-09-19T15:21:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xchangrey](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/xchangrey/32/89353_2.png) [@xchangrey](https://forum.freecodecamp.org/u/xchangrey)\
**Post date:** [September 19, 2018, 3:21pm UTC](https://forum.freecodecamp.org/t/foreach-and-rich-text-editor/228202/1 "2018-09-19T15:21:40Z")

</div>

Hi! I’m trying to create multiple instances of an squire rich text editor.. it seems my code only runs correctly on the last iteration. Please help.

```auto
//HTML
<div id="editor" class="doc ui_qtext_rendered_qtext" contenteditable="true" data-kind="doc" placeholder="" style="min-height: 500px;"> </div>
        <br>
<div id="editor1" class="doc ui_qtext_rendered_qtext" contenteditable="true" data-kind="doc" placeholder="" style="min-height: 500px;background:green;"> </div>

//JS
// Get all the instances of the doc
var divs = Array.from(document.getElementsByClassName( 'doc' ));

//Initialize editor in each div
var editor;

divs.forEach(function(div){
    editor = new Squire(div, {
      blockTag: "p",
      blockAttributes: { class: "ui_qtext_para" },
      tagAttributes: {
        a: {
          class: "external_link",
          target: "_blank",
          rel: "noopener nofollow",
          "data-qt-tooltip": ""
        }
      }
    });
})

```

---

<div class="post-metadata">

**Author:** ![xchangrey](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/xchangrey/32/89353_2.png) [@xchangrey](https://forum.freecodecamp.org/u/xchangrey)\
**Post date:** [September 19, 2018, 5:42pm UTC](https://forum.freecodecamp.org/t/foreach-and-rich-text-editor/228202/3 "2018-09-19T17:42:29Z")

</div>

Thanks! I don’t know how to say it. But say I want to bold a certain area in #editor, the bold command is applied in the last instance, in the example above #editor1… when it should be separate for each editable content.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [February 2, 2021, 11:30am UTC](https://forum.freecodecamp.org/t/foreach-and-rich-text-editor/228202/6 "2021-02-02T11:30:08Z")

</div>

Closed on February 2, 2021, 11:30am UTC


