I am learning HTML, CSS and JavaScript. Now I want to write the document title in a <p>
tag and I wrote this HTML file:
<!DOCTYPE html>
<html>
<head>
<title>HTML experimentation</title>
<script>
document.getElementById("document_title").innerHTML = document.title;
</script>
</head>
<body>
<p id="document_title">This text should be replaced by the title of the document</p>
</body>
</html>
According to the tutorials I find on the web, this should work. It does not. Why?
I have noted that if I do this:
<!DOCTYPE html>
<html>
<head>
<title>HTML experimentation</title>
<meta charset="utf-8">
<script type="text/javascript"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true
}
});
document.getElementById("document_title").innerHTML = document.title;
</script>
</head>
<body>
<p id="document_title">This text should be replaced by the title of the document</p>
</body>
</html>
it works. This, however, does not seem to be the way of making what I want.