-10

I want to display title in the browser using title tag. I used

<script>$(document.title).html('title');</script>
Ali Khan
  • 108
  • 2
  • 7

2 Answers2

5
<script type="text/javascript"> document.title = "123"; </script>
brickBreaker
  • 329
  • 2
  • 10
  • I tried like this – Ali Khan Sep 16 '13 at 13:53
  • @AliKhan, the second parameter for `pushState` already does what you need. the `pushState` syntax is `pushState(state, title, url)`. See [MDN pushState docs](https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history#The_pushState().C2.A0method) – dcro Sep 16 '13 at 13:58
  • the second parameter of pushstate is not supported by browsers (except Firefox I think) – Fez Vrasta Sep 16 '13 at 14:05
0

Try this:

You should use document.title="add your new title here";

But using jquery is not the preferred way for this change in the html document. Its slower as well as not supported in IE6/7 I believe.

$(document).ready(function ()
{
    $('title').text("add you new title here");
});
Siddharth Pandey
  • 3,402
  • 1
  • 25
  • 52
  • 1
    title must be changed with `document.title = "title"`, it doesn't need jQuery, which is a DOM editor framework. – Fez Vrasta Sep 16 '13 at 13:51
  • @FezVrasta It can be done using document object, I agree. But as such the user has asked with the jquery usage in the question, I have used the above way. And It works. I have just tested as well. Please remove your -1 vote to my answer. – Siddharth Pandey Sep 16 '13 at 13:53
  • @FezVrasta your comment in my answer is wrong with a must in it. It can be done in both the ways! I believe, it depends on the author how they want to do it. The only difference is the above is not supported in IE. Are you giving me -1 for this reason??????? – Siddharth Pandey Sep 16 '13 at 13:57
  • *jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.* As jQuery says, it's a document manipulation library. Use jQuery for it is slower also. – Fez Vrasta Sep 16 '13 at 13:58
  • ah and in your way Internet Explorer 7< crashes. – Fez Vrasta Sep 16 '13 at 14:00
  • @FezVrasta well jquery is for DOM manipulation. I know the above answer fails in ie6/7. I am also aware that we should avoid jquery where we can directly write using plain javascript. I answered in the jquery way coz the author of the question wanted in a jquery way. And he has also tagged jquery in this question. – Siddharth Pandey Sep 16 '13 at 14:04
  • so specify in your answer that in Internet Explorer 7 and less and in other minor browsers your code will make the entire javascript parser fail in error. And also specify that using jQuery is slower. – Fez Vrasta Sep 16 '13 at 14:06
  • @FezVrasta Yeah, will surely take care from next time. Could you please remove ur downvote from my answer. and I will delete it then or modify it with support info. – Siddharth Pandey Sep 16 '13 at 14:09
  • @FezVrasta I've modified my answer to give more info. cheers – Siddharth Pandey Sep 16 '13 at 14:14