max2020 max2020 - 1 year ago 84
jQuery Question

jQuery code need to translate to vanilla so I can use in Angular

I have this code on a template and I'm transfering the code to Angular 4 but it doesn't like the $ on jquery so I need a way to either be able to use it on Angular 4 or just translate it to pure js so I can use it.

Here's the code:

$('#toggle-btn').on('click', function (e) {

e.preventDefault();

if ($(window).outerWidth() > 1194) {
$('nav.side-navbar').toggleClass('shrink');
$('.page').toggleClass('active');
} else {
$('nav.side-navbar').toggleClass('show-sm');
$('.page').toggleClass('active-sm');
}
});


How can I do this?

Jim Jim
Answer Source

Without adding the jQuery package:

declare var $: any;

and if you need typescript definition then add this package to your package.json

"@types/jquery": "^2.0.45",

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download