# Any code for making text inside \[square brackets\] turn green?

**URL:** <https://forums.ankiweb.net/t/any-code-for-making-text-inside-square-brackets-turn-green/56987>\
**Category:** Help\
**Created:** [March 10, 2025, 10:12am UTC](https://forums.ankiweb.net/t/any-code-for-making-text-inside-square-brackets-turn-green/56987 "2025-03-10T10:12:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ewerton](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@Ewerton](https://forums.ankiweb.net/u/Ewerton)\
**Post date:** [March 10, 2025, 10:12am UTC](https://forums.ankiweb.net/t/any-code-for-making-text-inside-square-brackets-turn-green/56987/1 "2025-03-10T10:12:24Z")

</div>

any code for making text inside [square brackets] turn green?

---

<div class="post-metadata">

**Author:** ![mausprz](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@mausprz](https://forums.ankiweb.net/u/mausprz)\
**Post date:** [March 30, 2025, 7:23pm UTC](https://forums.ankiweb.net/t/any-code-for-making-text-inside-square-brackets-turn-green/56987/2 "2025-03-30T19:23:20Z")

</div>

You could easily achieve what you want via JavaScript with something like the following code:

```auto
document.addEventListener("DOMContentLoaded", () => {
  document.querySelectorAll(".green-brackets").forEach((element) => {
    element.innerHTML = element.innerHTML.replace(/\u005B([^\u005D]+)\u005D/g, '<span style="color: green;">[$1]</span>');
  });
});

```

This basically waits for the card to be fully loaded `DOMContentLoaded` then selects all elements with the class `green-brackets` to replace its contents with the same text wrapped in a `<span>` that applies the green CSS color.

This approach modifies the `innerHTML` property so avoid using it on elements containing interactive or complex content to prevent breaking event listeners or reloading already loaded images.

---

<div class="post-metadata">

**Author:** ![matta](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/matta/32/5126_2.png) [@matta](https://forums.ankiweb.net/u/matta)\
**Post date:** [March 31, 2025, 12:29am UTC](https://forums.ankiweb.net/t/any-code-for-making-text-inside-square-brackets-turn-green/56987/3 "2025-03-31T00:29:17Z")

</div>

You can place a around the content and then update the style at the bottom of the card.

For example: `<span class="green-text">*my text*</span>` .

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [April 30, 2025, 12:29am UTC](https://forums.ankiweb.net/t/any-code-for-making-text-inside-square-brackets-turn-green/56987/4 "2025-04-30T00:29:52Z")

</div>

Closed on April 30, 2025, 12:29am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
