Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery blinking title

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);
like image 508
Linas Avatar asked Mar 22 '12 21:03

Linas


2 Answers

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)

like image 77
Naftali Avatar answered Oct 22 '22 12:10

Naftali


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);
like image 40
Travis J Avatar answered Oct 22 '22 10:10

Travis J