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);
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);
Share
Improve this question
asked Mar 22, 2012 at 21:32
LinasLinas
4,40819 gold badges74 silver badges119 bronze badges
2
-
"#title"
refers toid="title"
for example. "title" may not refer todocument.title
. Can you show us the html definition of the<title>
tag? – Travis J Commented Mar 22, 2012 at 21:38 -
The code works for me as-is in FF11, of course an empty
<title>
just shows the URL instead, might want to try something like<tons of spaces><dot>
– No Results Found Commented Mar 22, 2012 at 21:39
2 Answers
Reset to default 6Use 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);