JaamySK
JaamySK

Reputation: 99

a JavaScript don't return $(window).innerWidth()

I am not so familiar with JavaScript and jQuery but I am trying to learn using them by making a test local web page for my self , some days ago I search for making a raining background using js and I found this amazing demo.

It looks great and I start to read it's files and codes but I got a problem it has a index.js and an index.min.js , the source html is using the .min one and its okay but I wanted to make a change to it and in the middle of this code I wanted to change something and use $(window).innerWidth() , although that the jquery.js is added in my html my index.min.js doesn't understand it, even when I say window.alert($(window).innerWidth()); it doesn't work , however window.alert("test"); works , my problem is that when at the same position in index.js file ( not the .min one ) I add my code ( window.alert($(window).innerWidth());... ) it works , I want to know what is the difference? why my index.min.js file seems not to understand jquery.

I tried to understand the differences between the index.js and index.min.js in this demo and I didn't catch anything , but the index.js is starting with (function e(.....) ....) but the index.min.js is starting with !function e(..)... I don't know what are they and I taught maybe this difference is causing problem , but I don't know js a lot so I don't know what to do...

rain-water-effect-experiments

Upvotes: 0

Views: 361

Answers (1)

epascarello
epascarello

Reputation: 207501

From the jQuery documentation for innerWidth:

This method is not applicable to window and document objects; for these, use .width() instead.

Now that should not cause the alert to not appear. Either code where you have the alert is not being triggered. Or you have an error message in the console saying Uncaught ReferenceError: $ is not defined(…) or some other error. If $ is not defined, than either jQuery is not on the page OR it is using an alias such as jQuery(window).width()

Upvotes: 3

Related Questions