Home >Web Front-end >JS Tutorial >How to set title in javascript
In javascript, you can use the title attribute to set the title; the title attribute can set or return the title of the element, the syntax format is "document.title = "title value""
The operating environment of this tutorial: Windows 7 system, ECMAScript version 5, Dell G3 computer.
title is a special node element in html. Because it can use doucment.getElementsByTagName("title")[0]
to get its title, but it cannot be used doucment.getElementsByTagName("title")[0]
Use to change its value.
However, there is always a solution. In javascript, the method to modify the title is:
document.title = 'xxxxxx' ;
Example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>旧标题,需要修改</title> </head> <body> <script> document.title = "新标题"; </script> </ody> </html>
Rendering:
##between Use
document.getElementsByTagName() to obtain or modify the node elements;
documentElement represents everything in the middle of
.
The reason why js will use document.title instead of the title of the web page is that tags such as title, head, and body are the only default tags, so
document.title and
document.body can find the results directly.
document.title has only one attribute (it can also be said to have no attributes), and
document.title itself is
documentAn attribute of the object, rather than one of its sub-objects, use
document.title="" to change the title.
Programming Video! !
The above is the detailed content of How to set title in javascript. For more information, please follow other related articles on the PHP Chinese website!