Where to insert Javascript Flashcards

The Tag In HTML, JavaScript code must be inserted between and tags.

1
Q

The Script> Tag
In HTML, JavaScript code must be inserted between and tags.

h2>JavaScript in Body /h2>

A

script>

document.getElementById(“demo”).innerHTML = “My First JavaScript”; /script>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

JavaScript in head>
In this example, a JavaScript function is placed in the section of an HTML page.

The function is invoked (called) when a button is clicked:

A
script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Paragraph changed.";
}
/script>
/head>
body>

h2>JavaScript in Head/h2>

p id=”demo”>A Paragraph./p>

button type=”button” onclick=”myFunction()”>Try it/button>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

JavaScript in body>
In this example, a JavaScript function is placed in the body> section of an HTML page.

The function is invoked (called) when a button is clicked:

A

button type=”button” onclick=”myFunction()”>Try it/button>

script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Paragraph changed.";
}
/script>

Placing scripts at the bottom of the body> element improves the display speed, because script interpretation slows down the display.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

External JavaScript
Scripts can also be placed in external files:

External scripts are practical when the same code is used in many different web pages.

JavaScript files have the file extension .js.

To use an external script, put the name of the script file in the src (source) attribute of a script> tag:

A

script src=”myScript.js”>/script>

script src=”/js/myScript1.js”>/script>

script src=”myScript1.js”>/script>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly