简体   繁体   中英

Newbie stuck with jQuery alerts not prompting notifications in browsers

I started learning jQuery on thenewboston.com and got stuck after a dozen tutorials. When I was learning JavaScript, I had no problem with alerts and prompts - they would pop up in the browser. I started having problems after I stared learning jQuery.

I have a simple code that should count all the elements on the page and prompt user the number of elements.

For index.html file:

<html>
<head>
</head>
<body>

    <p>Some text.</p>

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/selectors.js"></script>
</body>
</html>

For selectors.js file:

var count = $('*').length;
alert(count);

jquery.js is filled with code downloaded from the official jQuery site (compressed production version).

The code you see here is provided by thenewboston.com instructor, and I checked it dozens of times for mistakes (the videos appear a bit older, don't know if something drastically changed in the meantime). Also, file architecture is fine. Both jquery.js and selectors.js are within js folder, and index.html is in root.

What I try so far after googling:

  • tried Firefox and Chrome
  • tinkered with permission settings in both browsers (turned notifications off and on)
  • tried putting the -script- code within the -head- tags
  • tried changing type="text/javascript" to type="application/javascript" within -script- tags

Sorry, I changed <> symbols with -- because I had some formatting issues within bulleted lists.

I tried researching, but I couldn't find a solution to this problem. I found something similar (I think on stackoverflow even), and the OP managed to find a solution by turning his browser notifications on.

This code works just fine .

var count = $('*').length;
alert(count);

You can even run it in the dev console, and it works.

Okay, nvm guys I found a solution...

I was using Firefox when I was downloading jQuery. What happened was that Firefox opened a new tab with all the code after clicking download. I copy-pasted that code to my empty text file and called it jQuery.js.

Now using Chrome, I downloaded it again, and it was the real deal. I just renamed it, and put it in the js folder, and voila. feeling stupid

Thx for the answers and effort guys!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM