Opencart has been using the jQuery library for a long time now. In doing some research I found that there were not really a whole lot of articles out there written about OpenCart and jQuery so I’ve decided to write one. The purpose of this article will be to shed some light on what jQuery is and how it relates to OpenCart 2.0 and also I will give some examples on how to write jQuery just in cast you have decided to draft your own extension which may or may not involve the library. In truth if you have already developed your own custom extension and have copied existing jQuery code format you may not even realize you’re writing jQuery…..as the syntax is a little different than default JS
What is jQuery
How to find the reference in Opencart 2.0
On your keyboard just press CONTROL F to bring up the search and search for the following key word: “jquery”
You will then find this script reference:
Now if you actually click on the script link you will see a huge page of jumbled up code which is the MINIFIED version of the jQuery library. This, is the heart. This is where all of the plugins you are using or procedures you are using get their form, from the heart. Without the base you couldn’t instantiate any methods. Some websites call the jQuery library from Google Repository or elsewhere, and some keep the script in house. Opencart obviously includes it in the upload.
Now let’s show you the difference between jQuery syntax, and normal JS syntax when writing the exact same line of code.
To simulate a simple procedure let’s look for an element’s ID and apply a hide() function to that element.
$( "#target" ).hide();
document.getElementById("target").style.visibility = 'hidden';