I have an HTML element <title>that I want to dynamically change depending on other elements. I tried using document.getElementsByTagName('title').innerHTML = dynamicContent, but that didn't seem to work. I have seen this before, but I cannot figure out exactly how to do this.
<title>
document.getElementsByTagName('title').innerHTML = dynamicContent
Do you mean the element <title>in <head>on the page?If so, the change document.titleshould do the trick.
<head>
document.title
getElementsByTagName() returns a NodeList, so you need to select one element:
getElementsByTagName()
document.getElementsByTagName('title')[0].innerHTML = dynamicContent
There is also a shortcut for the title:
document.title = dynamicContent
a) document.title= 'blah';
b).textContent .innerText
Source: https://habr.com/ru/post/1774743/More articles:Как получить все записи из LinkedHashMap в Java? - javaJPEG: dimensions and compression - compressionTop Xquery Function - xqueryКакая методология программирования используется для проекта Final Year? - methodologyHow to redirect python runtime errors? - pythonN-tier architecture without a dataset (a dataset sounds bad for performance) - performanceThe best way to keep a constant view of all the views in the navigation controller - iphoneHow to add Find function to IList - listHow to select nth jQuery object in jQuery collection? - javascriptCan anyone suggest a way to track every function call? - cAll Articles