max2020 max2020 -3 years ago 131
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) {


if ($(window).outerWidth() > 1194) {
} else {

How can I do this?

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