Currently I have a custom block loaded almost last on the page containing:
<script type="text/javascript" src="/test.js"></script>
This script is pretty much the usual stuff, just manipulating HTML of my product page.
jQuery.noConflict();
 jQuery(document).ready(function($) {
 $(window).load(function() {
 {
 Do stuff with various HTML elements;
 }
 });
});
However, this method only seems to work as intended in Chrome. In Firefox, it just throws jQuery not defined, despite Magento 2 obviously having a local copy of jQuery called very early on the page.
Any ideas on how to get this working in Firefox? (Or better yet, how to do this properly, as I have a feeling I'm skirting round a lot of Magento's intended JS usage.)
2 Answers 2
add js like that
require([ 'jquery', 'jquery/ui'], function($){ $(document).ready(function($) {
 $(window).load(function() {
 {
 Do stuff with various HTML elements;
 }
 });
}); });
- 
 Perfect, thank you so much, this had been driving me crazy.Niall Storie– Niall Storie2016年02月22日 11:38:42 +00:00Commented Feb 22, 2016 at 11:38
- 
 There is a !domReady plugin included within the require implementation btw.Ben Crook– Ben Crook2016年12月23日 13:52:43 +00:00Commented Dec 23, 2016 at 13:52
- 
 How to use the !domReady? window.load and document.ready seem to fire a bet prematurely for meharri– harri2017年08月04日 10:17:31 +00:00Commented Aug 4, 2017 at 10:17
- 
 [ 'jquery', 'jquery/ui, 'domReady!'] is this all that is required for this?harri– harri2017年08月04日 10:25:29 +00:00Commented Aug 4, 2017 at 10:25
You can use your custom jquery function by:
 require([ 'jquery', 'jquery/ui'], function($){ 
 $(document).ready(function($) {
 alert("Hello"); //Do Your jQuery Code
 });
 });
- 
 i used as above in my module but some time it fails, can you please see once the below question magento.stackexchange.com/questions/220884/…inrsaurabh– inrsaurabh2018年04月04日 11:19:54 +00:00Commented Apr 4, 2018 at 11:19