[英]How do you change the name of a root element in JSON with javascript?
[英]How do you change the <title> element with javascript?
我有一個HTML <title>
元素,我想根據其他元素動態更改。 我嘗試使用document.getElementsByTagName('title').innerHTML = dynamicContent
但這似乎不起作用。 我以前看過它,但我似乎無法弄明白該怎么做。
你的意思是頁面<head>
中的<title>
元素嗎?
如果是,那么改變document.title
就可以了。
getElementsByTagName()
返回一個NodeList,因此您需要選擇一個元素:
document.getElementsByTagName('title')[0].innerHTML = dynamicContent
還有一個標題的快捷方式:
document.title = dynamicContent
你可以操縱
a)document.title ='blah';
b).textContent或.innerText取決於瀏覽器
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.