JavaScript
Article

jQuery Get Current Page Title

By Sam Deering

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.

var current_href = $(location).attr('href');
var current_title = $(document).attr('title');
  • Pingback: jQuery Get Current Page Title | Web Design Northamptonshire()

  • Pingback: jQuery Get Current Page Title « Big Engine Media()

  • http://www.mywebsitedesignersblog.com Andy Newby

    Are you sure??? For me it doesn’t work. Managed to work out this does work though:

    var current_href = $(location).attr(‘href’);
    var current_title = $(document).attr(‘title’);

    Just thought I would share in case anyone else has this problem ;)

    • http://jquery4u.com/ jQuery4u

      Thanks Andy, post updated.
      Sam

  • http://twitter.com/carolskelly Carol Skelly

    Thanks Andy, that worked for me too.

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in JavaScript, once a week, for free.