-1

I have created a Homepage using the shopping world and its element. Now I am trying to apply some jQuery codes on some elements, but it is not working. Could it be because the page is loading with AJAX?

My Custom Javascript is added to the theme so I can see it, but it's not having any effect on the page. How can I make it work?

I have created the js file in:

/src/js/myJsFile.js

And included this file in Theme.php of my active theme as follows:

protected $javascript = ['src/js/custom-scripts.js'];
Jim Simson
  • 2,774
  • 3
  • 22
  • 30
Xabby
  • 435
  • 6
  • 26
  • Make sure your script is waiting for [DOMContentLoaded](https://stackoverflow.com/questions/2414750/difference-between-domcontentloaded-and-load-events) – Will Nov 08 '18 at 06:58
  • I have found another way to handle this: jQuery (document) .ajaxComplete (function () { .... }); – Xabby Nov 08 '18 at 07:55

2 Answers2

1

Just Wrap Your JS Custom Code in the follow function it will work all fine for you.

jQuery (document) .ajaxComplete (function () { //you code here ... });
Xabby
  • 435
  • 6
  • 26
1

Shopware actually has an event that is triggered when an emotion element (e.g. shopping world is shown):

$.subscribe('plugin/swEmotion/onShow', function () {
    // your code goes here
});
mbrandau
  • 544
  • 3
  • 14