I have an HTML document as follows:
desusifyValue = 0; function desusify() { if (desusifyValue == 1) { document.getElementById("title").innerHTML = "Incremental Adventure"; desusifyValue = 0; } else { document.getElementById("title").innerHTML = "Art Project"; desusifyValue = 1; } }
<button onlick="desusify()">Desusify Title</button>
But when I click the button, the title doesn't change. Am I doing something wrong?
<button onlick="desusify()">Desusify Title</button>
should be
<button onclick="desusify()">Desusify Title</button>
onlick --> onclick
onclick
and not onlick
.<button onclick="desusify()">Desusify Title</button>
document.getElementById("title").innerHTML = "Art Project";
should be
window.document.title = "Art Project";
desusifyValue = 0; function desusify() { if (desusifyValue == 1) { window.document.title = "Incremental Adventure"; desusifyValue = 0; } else { window.document.title = "Art Project"; desusifyValue = 1; } } document.getElementById("title").innerHTML = "Art Project";
<button onclick="desusify()">Desusify Title</button>
Also at the place of desusifyValue = 0;
try using let desusifyValue = 0;
. Note only on the first one.
For your task, the window object has a window.document.title property. You can change it like this
window.document.title = "Art Project";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.