22

How can I modify the existing title to the document with Jquery as mouseover title change like that on facebook title link.

Jordan
  • 29,324
  • 6
  • 51
  • 63
ukung
  • 292
  • 1
  • 4
  • 12
  • You can see an example jQuery code [here](http://jquery-howto.blogspot.com/2012/12/change-document-tab-title-jquery.html). – Uzbekjon Jan 29 '13 at 14:27
  • possible duplicate of [Changing the page title with Jquery](http://stackoverflow.com/questions/7173596/changing-the-page-title-with-jquery) – kapa Jul 08 '14 at 08:46
  • Possible duplicate of [How to dynamically change a web page's title?](https://stackoverflow.com/questions/413439/how-to-dynamically-change-a-web-pages-title) – vrintle Nov 09 '18 at 17:05

4 Answers4

35

You don't need jQuery.

document.title = 'My new title here';
Jordan
  • 29,324
  • 6
  • 51
  • 63
10

With javascript. jQuery won't help you here:

document.title = 'New Title';

You can insert that into a jQuery mouseover callback function if you want.

Paul
  • 130,653
  • 24
  • 259
  • 248
7

I'll extend on these other answers, this code should do it in entirety, just be sure to change the class in the selector, and the new Title Text.

(function(){
    var oldtitle;
    jQuery('a.yourlink').hover(
        function () {
           oldtitle = document.title;
           document.title = 'Your New Title';
        },
        function () {
            document.title = oldtitle;
        }
    );
})();

Here is a jsfiddle demo I made that changes the text of the object, rather than the window title: http://jsfiddle.net/MpZGf/1/

Paul
  • 130,653
  • 24
  • 259
  • 248
Toby
  • 128
  • 6
  • It looks like `oldTitle` will be out of scope when it's needed the second time. – bbg Jul 16 '11 at 05:09
  • This won't work. oldtitle won't exist when the 2nd function is called. You have to move oldtitle up to a higher scope or save it somewhere else. – jfriend00 Jul 16 '11 at 05:09
  • 1
    wouldn't it be better to wrap the lot in a function and not have to attach extra 'properties' to the document like here - http://jsfiddle.net/aranm/gUsnC/2/ – Aran Mulholland Jun 13 '12 at 04:38
3

Try:

document.title = 'title';
The Mask
  • 15,697
  • 36
  • 104
  • 172