# Need help understanding how turbo works

**URL:** <https://discuss.hotwired.dev/t/need-help-understanding-how-turbo-works/3622>\
**Category:** General\
**Created:** [December 23, 2021, 5:43pm UTC](https://discuss.hotwired.dev/t/need-help-understanding-how-turbo-works/3622 "2021-12-23T17:43:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Svashtar](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/svashtar/32/2436_2.png) [@Svashtar](https://discuss.hotwired.dev/u/Svashtar)\
**Post date:** [December 23, 2021, 5:43pm UTC](https://discuss.hotwired.dev/t/need-help-understanding-how-turbo-works/3622/1 "2021-12-23T17:43:52Z")

</div>

So, i am integrating a template into Rails 7.0 project, where JS is already written to some extend. A lot.  
And it is driving me nuts, because JS is triggered fine on first load, then after clicking some link (seems like by default they are turbo enabled) this exact same JS is somehow not triggered at all.

This is the code for example:

```auto
// On document ready
if (document.readyState === 'loading') {
   document.addEventListener('turbo:load', KTMenu.init);
} else {
  KTMenu.init();
  console.log("fired")
}

```

As you can see i’ve added log to console, to see what is going on, and when page is delivered by turbo, the “else” part is definitely triggered, but not working anymore.

Can please, someone explain why this is not working?  
Should i add an event listener here (to some other event, as load already happened)?  
I don’t get it ☹

Thanks

---

<div class="post-metadata">

**Author:** ![rockwell](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/rockwell/32/1884_2.png) [@rockwell](https://discuss.hotwired.dev/u/rockwell)\
**Post date:** [December 26, 2021, 7:13pm UTC](https://discuss.hotwired.dev/t/need-help-understanding-how-turbo-works/3622/2 "2021-12-26T19:13:49Z")

</div>

> [@Svashtar](#):
>
> As you can see i’ve added log to console, to see what is going on, and when page is delivered by turbo, the “else” part is definitely triggered, but not working anymore.

What do you mean not working anymore?. When using the browser back-button, when does the issue occur?.

---

<div class="post-metadata">

**Author:** ![Svashtar](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/svashtar/32/2436_2.png) [@Svashtar](https://discuss.hotwired.dev/u/Svashtar)\
**Post date:** [December 26, 2021, 7:40pm UTC](https://discuss.hotwired.dev/t/need-help-understanding-how-turbo-works/3622/3 "2021-12-26T19:40:36Z")

</div>

It happens on any navigation action. For example, navigating to another page. It works when app is loaded for the first time, any further ‘clicking around’ not loading JS properly anymore.

---

<div class="post-metadata">

**Author:** ![rockwell](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/rockwell/32/1884_2.png) [@rockwell](https://discuss.hotwired.dev/u/rockwell)\
**Post date:** [December 26, 2021, 7:56pm UTC](https://discuss.hotwired.dev/t/need-help-understanding-how-turbo-works/3622/4 "2021-12-26T19:56:25Z")

</div>

what does the `KTMenu` class do exactly?

---

<div class="post-metadata">

**Author:** ![Svashtar](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/svashtar/32/2436_2.png) [@Svashtar](https://discuss.hotwired.dev/u/Svashtar)\
**Post date:** [December 26, 2021, 8:28pm UTC](https://discuss.hotwired.dev/t/need-help-understanding-how-turbo-works/3622/5 "2021-12-26T20:28:14Z")

</div>

It prepares the main menu of the app, dropdowns mainly, some other stuff. Dropdowns are the ones not working, at least that’s what’s apperant.

---

<div class="post-metadata">

**Author:** ![rockwell](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/rockwell/32/1884_2.png) [@rockwell](https://discuss.hotwired.dev/u/rockwell)\
**Post date:** [December 26, 2021, 9:51pm UTC](https://discuss.hotwired.dev/t/need-help-understanding-how-turbo-works/3622/6 "2021-12-26T21:51:27Z")

</div>

You want to hide the dropdowns?

---

<div class="post-metadata">

**Author:** ![xujianmin](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/xujianmin/32/3871_2.png) [@xujianmin](https://discuss.hotwired.dev/u/xujianmin)\
**Post date:** [September 25, 2024, 6:20am UTC](https://discuss.hotwired.dev/t/need-help-understanding-how-turbo-works/3622/7 "2024-09-25T06:20:55Z")

</div>

Hi, I got the same issue when to integrate a bootstrap theme. Have you got this solved?
