Difference between internal and external Scripting in jQuery ?

Hello All,

In the previous jQuery blog, we saw about the jQuery implementation.

Today we going to see the difference of internal and external scripting.

Internal scripting :

Internal scripting means writing the script functions in the same tag/page itself.

E.g.

<!doctype html>
<html lang ="en">
<head>
<meta charset="utf-8">
<title> Selectors</title>
</head>
<link rel="stylesheet" type="text/css" href="css/style.css"> 
<p onclick=alert("WELCOME")>www.geeks.gallery</p>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>


</body>
</html>

In the above example, onclick function has been declared in the p tag itself.

External Scripting:

External scripting means keeps the script in a separate js file.

E.g.
1. At .php file :

<!doctype html>
<html lang ="en">
<head>
<meta charset="utf-8">
<title> Selectors</title>
</head>
<link rel="stylesheet" type="text/css" href="css/style.css"> 
<p id="para">www.geeks.gallery</p>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>


</body>
</html>

2. At .js File:

$('#para').click(function() {
alert("Welcome");
} );

Note:
In the above code we used ids in.php file. such that we can call the functions from external scripting .js file

The External scripting is preferable than the internal scripting. Because we can use the code effectively in external scripting than internal.
Writing the script in external scripting way is the best practice method.

Leave a Reply

Your email address will not be published. Required fields are marked *