JQuery flashing title

So, I need to have a blinking title, this code should work, but for some reason it does not.

Now the console continues to show me the correct title, but the title in my browsers does not 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); 
+6
source share
2 answers

Use document.title = ... <---

You are simply editing an attribute that does nothing.


Try the following:

 setInterval(function(){ var title = document.title; document.title = (title == "test" ? "none" : "test"); }, 1000); 

See the header in this demo every second from test to none . ( full violin )

+6
source

Use the direct link:

 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); 
+1
source

Source: https://habr.com/ru/post/911450/


All Articles