Why does scrollspy require JQuery?

Why does scrollspy require JQuery?
0.0 0

#1

For a while I was struggling to get scrollspy to work on my portfolio (http://codepen.io/drhectapus/pen/zoqBzK).

After browsing the forum, I figured that I needed to add JQuery. Specifically, JQuery first then bootstrap.js

But why is this case?? I thought scrollspy was specifically a bootstrap feature.


#2

Hi, all bootstrap plug ins require jQuery.

Or to put it another way, bootstrap is dependant on jQuery.

The reason you need to add it before bootstrap is because your browser will load the jQuery first so bootstrap can reference it. If you put it afterwards, bootstrap would not know how to accomplish the jQuery functions as it has never heard of jQuery at this point. It will most likely return a $ is not defined type error.

If you download bootstrap it includes it although you still need to link to the local file, if your using A CDN (i.e. a link tag in codepen settings or HTML head) then you’ll need to add jQuery separately with a script tag.

See here under what’s included-

http://getbootstrap.com/getting-started/

EDIT, to answer your original question -

Scroll spy is a Bootstrap feature. but it requires Javascript. The javascript thay have written uses jQuery. Most likely to save some compatibility headaches.


#3

Makes sense. Thanks!