Home >Web Front-end >Front-end Q&A >How to modify the title of html in js
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.
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 = '需要设置的值';
Example
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>hello</title> </head> <body> <script type="text/javascript"> document.title = 'php中文网'; </script> </body> </html>
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('需要设置的值')
Example
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>hello</title> <script src="js/jquery-1.7.2.min.js"></script> </head> <body> <script type="text/javascript"> // $('title').html('php中文网'); $('title').text('php中文网'); </script> </body> </html>
[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!