cancel
Showing results for 
Search instead for 
Did you mean: 

How to use custom jquery / javascript in magento 2.0 ?

How to use custom jquery / javascript in magento 2.0 ?

Hi guys,

 

I just want to use a custom javascript file in my theme, but it doesn't work. Could somebody find my error?

I also tried to add my code directly into a .phtml file, but even that does not work.

 

So I created ../app/design/frontend/Myvendor/mytheme/requirejs-config.js

 

 

var config = {
map: {
    '*': {
        mainjs:	"js/main"
    }
}

 

 

Then I created ../app/design/frontend/Myvendor/mytheme/web/js/main.js

 

define([
    'jquery',
    'uiComponent',
],
function ($, Component) {
    'use strict';
    $(document).ready(function(){
		var footerMenu = document.getElementsByName('footerMenu');
		var radio;
		var x = 0;
		for(x = 0; x < footerMenu.length; x++){
		
		    footerMenu[x].onclick = function() {
		        if(radio == this){
		            this.checked = false;
		            radio = null;
		        }else{
		            radio = this;
		        }
		    };
		}
	});
    return Component.extend({});
});
1 REPLY 1

Re: How to use custom jquery / javascript in magento 2.0 ?

How to insert some JavaScript to a *.phtml template in the proper way (x-magento-init): https://mage2.pro/t/145