jQuery: Linking Our Files

Linking Files

HTML:(make a file and write this code and then save it as “index” make sure the extension is ‘.html’)

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>

Script(jQuery):(make a file and write this code and then save it as “script” make sure the extension is ‘.js’)

$(document).ready(function(){

});

Now, we have our files ready and all what we have to do is to link them. To do that, we will add a script tag.

Script tag:(added it before the closing of the head tag in the HTML file)

<!--Script tag -->
<script type="text/javascript" src="script.js"></script>

That’s it, We linked our files.

Explanation

    • $() tells jQuery that we will be doing something.
    • Putting document between the parentheses tells us that we’re about to work on the HTML document itself.
    • .ready(); is a function, or a basic action, in jQuery. It tells that as soon as the HTML document is ready it will run.
    • Whatever goes in .ready()‘s parentheses is the jQuery event that occurs as soon as the HTML document is ready.

NOTE: MAKE SURE TO DOWNLOAD JQUERY IN ORDER FOR THE CODE TO RUN OR YOU CAN USE A CDN.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s