# Перемещение элемента в JS в инициализаторе?

**URL:** https://meta.discourse.org/t/moving-element-in-js-in-an-initializer/360330
**Category:** Development
**Created:** [04.Апрель.2025 02:18:55 UTC](https://meta.discourse.org/t/moving-element-in-js-in-an-initializer/360330 "2025-04-04T02:18:55Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [04.Апрель.2025 02:18:55 UTC](https://meta.discourse.org/t/moving-element-in-js-in-an-initializer/360330/1 "2025-04-04T02:18:55Z")

</div>

У меня есть такой фрагмент кода:

В `javascripts/discourse/initializers`:

```js
import { apiInitializer } from "discourse/lib/api";
import CustomHeaderTopicButton from "../components/custom-header-topic-button";

export default apiInitializer((api) => {
  api.renderInOutlet("below-site-header", CustomHeaderTopicButton);
  
  document.addEventListener("DOMContentLoaded", function() {
    const newTopicBtn = document.getElementById("new-topic-button");
    const sidebar = document.getElementById("d-sidebar");
    if (newTopicBtn && sidebar) {
      sidebar.insertBefore(newTopicBtn, sidebar.firstChild);
    }
  });
});

```

И всё же кнопка не перемещается в боковую панель. Я что-то делаю не так?

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [04.Апрель.2025 02:36:05 UTC](https://meta.discourse.org/t/moving-element-in-js-in-an-initializer/360330/2 "2025-04-04T02:36:05Z")

</div>

Если вы пытаетесь добавить кнопку в верхнюю часть боковой панели, лучше использовать плагин-выход `before-sidebar-sections`.

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/a/6/7a62e7dea72ee7802f9b3a934786cfb54eb0334f.png)

Перемещение HTML, сгенерированного Ember, кажется не самой хорошей идеей.

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [04.Апрель.2025 02:52:40 UTC](https://meta.discourse.org/t/moving-element-in-js-in-an-initializer/360330/3 "2025-04-04T02:52:40Z")

</div>

Это… существует?? Вау, спасибо.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [04.Май.2025 02:53:28 UTC](https://meta.discourse.org/t/moving-element-in-js-in-an-initializer/360330/4 "2025-05-04T02:53:28Z")

</div>

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