How to modify the title of html in js

青灯夜游
Release: 2023-01-07 11:47:13
Original
7027 people have browsed it

JS method to modify html title: 1. Use the "document.title="value that needs to be set";" statement; 2. Use "$('title').html('value that needs to be set' )" or "$('title').text('value to be set')" statement.

How to modify the title of html in js

The operating environment of this tutorial: windows7 system, javascript1.8.5&&jquery1.7.2 version, Dell G3 computer.

Method 1: document.title method

After testing, the value of title can also be set through document.title.

document.title = '需要设置的值';
Copy after login

Example

    hello 
Copy after login

How to modify the title of html in js

Method 2: Using jQuery’s html() or text() method

Of course, if your project relies on jQuery, you can use the jq method to set it.

Both methods can be implemented in jq

$('title').html('需要设置的值') $('title').text('需要设置的值')
Copy after login

Example

    hello  
Copy after login

How to modify the title of html in js

[Recommended learning:javascript advanced tutorial

The above is the detailed content of How to modify the title of html in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!