A strange way to behave of JavaScript
- A simple XHTML: html.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>A very very simple valid XHTML file</title>
</head>
<body>
<h1>A very very simple valid XHTML file</h1>
<p id="content">Some very smart content</p>
</body>
</html>
- A JavaScript external file: js.js
function changeContent()
{
document.getElementById("content").innerHTML = "Some even more smart JS content";
}
- Adding the JS via the short notation doesn't work: short.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="js.js" />
<title>An XHTML file with short notation</title>
</head>
<body onload="changeContent();">
<h1>An XHTML file with short notation</h1>
<p id="content">Some very smart content</p>
</body>
</html>
- You have to write a closing tag: closing.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="js.js"></script>
<title>An XHTML file with short notation</title>
</head>
<body onload="changeContent();">
<h1>An XHTML file with short notation</h1>
<p id="content">Some very smart content</p>
</body>
</html>