Issue with mutating page title with jQuery
17 May 2013
If we have to change an element's content using jQuery we can use the html()
or text()
functions
provided by the library. This works like a charm until we are not dealing with title element in Internet Explorer
.
Yeah, I was surprised to see IE throwing error when asked to changed the title using jQuery's html() method. My code
$("title").html("Js Blog");
This works well in Chrome, Firefox, Safari.
The Solution
So how did i manage to change the title? I used the following code to change the page title.
document.title="Js Blog";
document.title
works well in all the browsers and is THE solution when we want to change the title.
Sometimes while using a library we are engrossed into it that don't realize that dom api already have a solution for it which is cross browser compatible.
More Information
blog comments powered by Disqus