Definition and Usage..
The title property sets or returns the title of the current document (the text inside the HTML title element)
Return Value: A String, representing the title of the documen
Syntax :
Return the title property: document.title
Set the title property: document.title = newTitle
CODING:The title property sets or returns the title of the current document (the text inside the HTML title element)
Return Value: A String, representing the title of the documen
Syntax :
Return the title property: document.title
Set the title property: document.title = newTitle
<!DOCTYPE html>
<html>
<head>
<title>My title</title>
</head>
<body>
<p>Click the button to display the title of the document.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.title;//also declare document.getElementsByTagName("TITLE")[0].text and assign value like ...text="..";
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
<html>
<head>
<title>My title</title>
</head>
<body>
<p>Click the button to display the title of the document.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.title;//also declare document.getElementsByTagName("TITLE")[0].text and assign value like ...text="..";
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
Comments
Post a Comment