Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the page title with Jquery

How to make dynamic changing <title> tag with jquery?

example: adding 3 > symbols one by one

> title >> title >>> title 
like image 656
Ilya Medvedev Avatar asked Aug 24 '11 10:08

Ilya Medvedev


People also ask

How can we set the page title in jQuery?

jQuery code snippet to get the current web page full title and store it in a variable for use with other scripts. This is the title you see on your browser header. Current page title: mytitle. Another way suggested by Andy.

How to set title dynamically in jQuery?

To set the title property on an element, use: $('#yourElementId'). prop('title', 'your new title');

How do I change the page title in JavaScript?

Use the querySelector() Method to Change the Page Title in JavaScript. We can use the document. querySelector() method to pick elements in a document. The title element can be chosen by giving the title element a selector parameter and retrieving the page's main title element.

What is title in JavaScript?

The title property sets or returns the value of the title attribute of an element, nothing but providing extra information regarding the element. This is mostly used as a tooltip, which displays the text on mouse hovering. Javascript has provided document. title() to get the title.


1 Answers

$(document).prop('title', 'test'); 

This is simply a JQuery wrapper for:

document.title = 'test'; 

To add a > periodically you can do:

function changeTitle() {     var title = $(document).prop('title');      if (title.indexOf('>>>') == -1) {         setTimeout(changeTitle, 3000);           $(document).prop('title', '>'+title);     } }  changeTitle(); 
like image 122
Gazler Avatar answered Nov 08 '22 13:11

Gazler