JavaScript Not Executing on Initial Template Rendering

17 Views Asked by At

I'm experiencing a problem where JavaScript isn't functioning as expected during the initial rendering of my web template (haml). Although I've included JavaScript code, it doesn't run on the initial page load. Interestingly, even a basic console.log statement doesn't appear in the console until I refresh the page.

this is what my template looks like

- if user.present?
  %div#button-container
    %a#my-test.button{'data-user-id' => user.id, :href => '#'}
      = image_tag('https://test.button.svg', id: 'Button', style: 'padding-top: 20px;')

:javascript
  console.log('Inside Javascript')
  $(document).ready(function() {
    console.log('Inside document.ready()')
  });

I'm finding it difficult to understand what the issue could be here. Neither console logs anything during the initial template rendering, but upon reloading the page, they log messages, indicating that the JavaScript is now functioning correctly.

0

There are 0 best solutions below