Home >Web Front-end >JS Tutorial >How to set title in javascript

How to set title in javascript

青灯夜游
青灯夜游Original
2021-04-01 16:22:257614browse

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""

How to set title in javascript

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:

How to set title in javascript

##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.

The title is a structural tag, which means that only nodetext can be added to the title; other elements cannot be added. So its use is special. In order to prevent errors in the code, js stipulates that the object

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.

For more programming related knowledge, please visit:

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn