1

I Try The Code But it doesnot working?

     <html>

       <head>

       <script>

    document.getElementbyId("title1").value="MyTitle";

         </script>

     <title id="title1"> </title>

      </head>

       <body>

        </body>

      </html>

Is that any methods are available in javascript?

1
  • Put the script block as a last child of body. Commented Aug 12, 2016 at 5:25

2 Answers 2

1
  1. Use document.title See the MDN Docs for document.title

<html>

<head>
  <title id="title1"></title>
</head>

<body>
</body>
<script>
  document.title = "MyTitle";
</script>

</html>

  1. If you are using DOM manipulation, do it after the element is loaded.

<html>

<head>
  <title id="title1"></title>
</head>

<body>
</body>
<script>
  document.getElementbyId("title1").value = "MyTitle";
</script>

</html>

Sign up to request clarification or add additional context in comments.

Comments

1

You can use document.title

<!DOCTYPE html>
<html>
<head>
  <title id="title1"> </title>
  <!-- note `<script>` element after `<title>` element -->
  <script>
    document.title = "MyTitle";
  </script>
</head>
<body>
</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.