Ticket #5881 (closed bug: duplicate)
document.title needs special handling in Internet Explorer
| Reported by: | hjess | Owned by: | john |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | core | Version: | 1.4 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
In IE (versions 6, 7 & 8 on my PC); a few issues:
jQuery('title').html() returns the title (== document.title)
jQuery('title').text() is empty
jQuery('title').text('new title')
and
jQuery('title').html('new title') both raise an error:
Error: Unexpected call to method or property access.
These all work in Firefox (I'm using 3.5.7). Finally, these work better in IE, but still not quite right :(
jQuery('title').attr('text') returns document.title
jQuery('title').attr('text','new title') sets document.title properly. However, the title displayed in the browser chrome reflects the new title only in IE6. In IE7/IE8, even though the value of document.title matches the title element's 'text' attribute, the browser chrome changes only when you set document.title.
Change History
comment:2 in reply to: ↑ 1 Changed 3 years ago by hjess
Replying to dmethvin:
Using the document.title property is the simple cross-browser way to set or retrieve the document title. IE just doesn't want to play right.
Agreed -- but we've progressed to the point where developers would rather use jQuery access to elements rather than their direct DOM0 counterparts -- I've seen code like this:
function getById(id) {return jQuery('#'+id)[0]}
So, given that, it would be nice if jQuery supported IE's weirdness.
comment:3 Changed 3 years ago by snover
- Status changed from new to closed
- Resolution set to wontfix
The correct way to set the title is to set document.title. Manipulating the DOM is incredibly slow and is very much the wrong way to do this.
comment:4 Changed 2 years ago by anonymous
I've been trying a few things, what works best is indeed the document.title property. However, if you want to use as much JQ as you can, I found that
$("title").innerHTML = $("title").attr("text", "New title");
works on IE8. A pointless workaround, if you ask me.
If anyone has a better idea...
comment:5 Changed 2 years ago by jitter
- Priority changed from major to low
- Resolution wontfix deleted
- Status changed from closed to reopened
- Component changed from selector to core
- Milestone 1.4.1 deleted
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Using the document.title property is the simple cross-browser way to set or retrieve the document title. IE just doesn't want to play right.