# Insert a div into the specified html code to wrap it

**URL:** <https://meta.discourse.org/t/insert-a-div-into-the-specified-html-code-to-wrap-it/319942>\
**Category:** Development\
**Created:** [August 3, 2024, 6:34am UTC](https://meta.discourse.org/t/insert-a-div-into-the-specified-html-code-to-wrap-it/319942 "2024-08-03T06:34:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![sheng\_hualuo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sheng_hualuo/32/430359_2.png) [@sheng\_hualuo](https://meta.discourse.org/u/sheng_hualuo)\
**Post date:** [August 3, 2024, 6:36am UTC](https://meta.discourse.org/t/insert-a-div-into-the-specified-html-code-to-wrap-it/319942/2 "2024-08-03T06:36:14Z")

</div>

```plaintext

<script type="text/discourse-plugin" version="0.8">
  api.onPageChange(() => {
    // 查找所有具有 avatar 类的 img 元素
    const avatarImages = document.querySelectorAll('img.avatar');

    avatarImages.forEach(img => {
      // 创建一个新的 div 元素，并设置其类名为 by9700
      const wrapper = document.createElement('div');
      wrapper.className = 'by9700';

      // 将 img 元素移入到新的 div 中
      img.parentNode.insertBefore(wrapper, img);
      wrapper.appendChild(img);
    });
  });
</script>

```

It’s like this, but the code doesn’t take effect

---

_[View the full topic](https://meta.discourse.org/t/insert-a-div-into-the-specified-html-code-to-wrap-it/319942)._
