var jq = document.createElement('script'); jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"; document.getElementsByTagName('head').appendChild(jq); // ... give time for script to load, then type (or see below for non wait option) jQuery.noConflict();
Here is what the above code is Doing:
1. It’s creating a new script element
2. It’s setting the source of the script to the jQuery CDN
3. It’s appending the script element to the head of the document
4. It’s telling the browser to wait until the script has loaded before executing the next line of code
5. It’s telling the browser to execute the next line of code, which is the jQuery.noConflict() function
The jQuery.noConflict() function is necessary because the browser already has a variable named $, and we don’t want to overwrite it.
Now that we have jQuery loaded, we can use it to select elements on the page.