So, i need to have a blinking title, this code should work, but for some reason it doesn't.
Now console keeps showing me correct title, but title in my browsers doesn't change, what could be wrong?
var blink = true;
setInterval(function(){
if(blink){
$("title").text("test");
blink = false;
console.log($("title"));
}else{
$("title").text("");
blink = true;
console.log($("title"));
}
}, 1000);
Use document.title = ...
<---
You are just editing an attribute which does nothing.
Try this:
setInterval(function(){
var title = document.title;
document.title = (title == "test" ? "none" : "test");
}, 1000);
See the title in this demo change from test
to none
every second. (full fiddle)
Use a direct reference:
var blink = true;
setInterval(function(){
var theTitle = document.getElementsByTagName("title")[0];
if(blink){
theTitle.text = "test";
//or theTitle.innerHTML = "test";
blink = false;
}else{
theTitle.text = "";
//or theTitle.innerHTML = "";
blink = true;
}
}, 1000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With