-3

I want to display a div tag as Webpage Title

Suppose my div tag

 <div id="songArtist"></div>

has a content of "Akon" then my title of page should be Akon

Adding div tag between this <title></title> is not working

Please help me..

Pete
  • 57,112
  • 28
  • 117
  • 166
Nisha Reddy
  • 9
  • 1
  • 5

5 Answers5

1

Check this -

Instead of Random Title it will show div content(Akon in this case).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Random Title</title>

</head>

<body>
<div id="songArtist">Akon</div>
<script>
document.title = document.getElementById("songArtist").innerHTML;
</script>
</body>
</html>
swapnesh
  • 26,318
  • 22
  • 94
  • 126
1

After any call to the function, object, request that changes the content of

 <div id="songArtist"></div>

dynamically, you can then call the below in Javascript;

 doocument.title = document.getElementById('songArtist').innerHTML;
Joberror
  • 5,860
  • 3
  • 20
  • 15
0

jQuery solution

Try this:

$(document).ready( function() {
    document.title = $('#songArtist').text();
});

If you want it to change on every change occurring to this div then you'd use:

$(document).ready( function() {
    $('div').on( '#songArtist', 'change', function() {
        document.title = $(this).text();
    });
});
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
0

You can change the title like this

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>hi</title>

</head>
<body>
    <div id='songArtist'> Welcome to this page </div>

       <script language="javascript" >
    document.title= document.getElementById('songArtist').innerHTML;
   </script>
</body>


</html>
Sandeep Kumar
  • 783
  • 1
  • 5
  • 13
  • Please see: http://stackoverflow.com/questions/3037725/is-it-wrong-to-place-the-script-tag-after-the-body-tag. You'll want to move that `script` chunk *before* the closing `body` tag. – James Donnelly May 01 '13 at 08:14
  • No we need to write this script at the end of body load. If we put the script before body tag then script will try to set the title before drawing the div control in body. And this code will not work. We only add the script on the top if we reference any file to do manupulation on body load. – Sandeep Kumar May 01 '13 at 08:20
  • Please look at the question I linked to. You have your script **outside** of the `body`. You want to add it just before the `

    ` tag.

    – James Donnelly May 01 '13 at 08:21
  • Oh.. Sorry for this. Yes you can write at the bottom of body tag. – Sandeep Kumar May 01 '13 at 08:24
-1

With PHP

<html>
    <head>
        <title><?php echo $page_title;?></title> 
    </head>
</html>

Static title.

   <html>
        <head>
            <title>
                Akon
            </title>
        </head>
    </html>