View video tutorial
HTML Script
HTML
<script>
tag specifies internal or external scripting resources for the document.
Script for document
<script>
can be used to specify internal script.
<script>
can be used to specify external script resources.
If multiple <script>
tags are used, they will be merged into one combining all.
<script>
tag can be placed any where in the document.
So the script can be put in <head>
tag or other places in the document.
Recommended place is just above the end tag of </body>
element.
<script>
function method() {
var t1 = document.getElementById("text1");
document.getElementById("p1").innerHTML=t1.value;
t1.style.backgroundColor = "#a1a1a1";
}
</script>
Learning with HTML Editor "Try it Now"
You can edit the HTML code and view the result using online editor.
The <script>
inside head tag.
Example
<!DOCTYPE html>
<html>
<!-- Example: script Tag -->
<head>
<title>Title goes here</title>
<script>
function method() {
var t1 = document.getElementById("text1").value;
document.getElementById("p1").innerHTML = t1;
}
</script>
</head>
<body>
<h1>script tag example.</h1>
<h2 id="p1"></h2>
<input id="text1" type="text" onkeyup="method()" placeholder="Type something here" />
</body>
</html>
Click on the "Try it Now" button to see how it works.
The <script>
just before the end of the </body>
tag.
Example
<!DOCTYPE html>
<html>
<!-- Example: script Tag -->
<head>
<title>Title goes here</title>
</head>
<body>
<h1>script tag example.</h1>
<input id="text1" type="text" onkeyup="method()" placeholder="Type something here"/>
<h2 id="p1"></h2>
<script>
function method() {
var t1 = document.getElementById("text1");
document.getElementById("p1").innerHTML=t1.value;
t1.style.backgroundColor = "#a1a1a1";
}
</script>
</body>
</html>
Click on the "Try it Now" button to see how it works.