To make coding javascript easier.
We're going to use Jay Query.
Jake Query is a javascript library that makes it easier to write JavaScript code different browsers
support javascript to varying degrees and Jake Query also removes inconsistencies between browsers.
So you know your code will work in as many browsers as possible.
There are some drawbacks to using Jake Query.
First it's additional code that your site has to download.
When someone opens your site in a browser it's not a major performance hater Tal But if you're going
with the fastest site possible you might want to consider using vanilla javascript instead vanilla javascript
is simply the javascript code that your browser supports by default.
You do have to be aware of differences between browsers though as not all browsers do things the same
way in javascript.
For the purposes of this course we're going to use a query as it's much faster to code using it and
the javascript code is much more concise and easier to read so we won't get distracted from seeing how
we can use Javascript in the context of P H P.
There are two ways we can add the jaquie reliably to our code.
J query is simply a file containing javascript that we need to load into our pages.
So the first way is to download it.
And save it with your code.
The Virgin you download might be slightly different to this but always try and download the latest version.
Unless you know you have a valid reason not to.
Newer versions of the library are backwards compatible with Previous Versions So there's no problem
using the latest version of J query with the javascript code.
We'll be learning here.
To add a query to this page we add a scrip tag with the path to the file we just downloaded we'll put
it before our own script file so that we can use jaquie dysfunctions in our own code.
You can load as many javascript files in separate script tags like this as you like.
As for where to put the script tags they can be in the head.
Are body sections of the team AML.
But in some browsers the page isn't displayed until all the code is loaded including seperate files
like this.
So if you have the script tags in the head section your page could take a bit longer to display by putting
the script references like this.
The end of the body section.
The page will be displayed sooner.
The other way to include Jake Query is to link to the file on a content delivery network R C D N A C
D N is a network of web servers that deliver files to a user based on their geographical location.
When you link to a hosted query file via see the n it will potentially arrive faster and more efficiently
to the user than if you hosted it on your own server.
So unless you have a good reason not to.
I recommend using a c d n to load J query.
There are various different C DNA available and they all work in the same way.
For example if we go to J queries o n c d n select the version we want.
We're shown the script tag code that we need which we can copy.
And paste it in our page.
In place of loading the local file these additional attributes are our security check used by the browser
to check the file hasn't been modified.
Now we have Jay Query loaded.
Let's convert this code to uja query instead.
Here we are getting the button element.
Based on its idea attributes and adding an event listener on the Click event that will run the say hello
function when the event occurs.
In other words when the button is clicked.
In J query to get an element based on its idae we do this then to run some code when the click event
occurs.
We just call the honoured method like that much more concise than the vanilla javascript code.
In the browser the code works as before showing the alert message when the button is clicked.