开发者

Anyway to link <title> to <div>?

Is there anyway to link the <title> to a <div> via javascript or php?

I tried

document.title.valu开发者_JAVA技巧e = document.getElementById("div").innerHTML;

but that didn't seem to work

I want to do this because I have multiple pages where I want the <title> to the be the same as what is in a <div>, but I don't want to handcode it.


You don't need document.title.value, just document.title works.

document.title=document.getElementById("div").innerHTML;

Offcourse, you need to execute this after your DOM loaded. Use the onload in the body or any onload function.


You don't need .value on the document.title. I would also use .innerText instead of .innerHtml.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜