Question

I want to display the field player but i can't:

<body>

       <header>
    <h1>My memory Game</h1>
</header>

<div id="timer">
    Player Name: 
    <span id="player-name">

               <script type='text/javascript'>

                sessionStorage.getItem('player');

                //alert("Your name is: " + sessionStorage.getItem('player'));    

               </script>    
    </span>
</div>

When i test it by using javascript alert everything work : the player name is desplayed without a problem Any idea please

Was it helpful?

Solution

Use this:

document.getElementById('player-name').innerHTML = 
     sessionStorage.getItem('player');

Fixed code:

<body>
    <header>
        <h1>My memory Game</h1>
    </header>
    <div id="timer">
        Player Name: 
        <span id="player-name">
        </span>
    </div>
    <script type='text/javascript'>
        document.getElementById('player-name').innerHTML = sessionStorage.getItem('player');
    </script>    

You should do some javascript tutorials. ​

OTHER TIPS

sessionStorage.getItem('player') returns a string. you should do something with it. like display in alert. - which is working according to your details...

once you have the value you can put it in element

ie:

myelement.inneHtml=sessionStorage.getItem('player')

this will write it into your span you should place the script tag below the span (i do not know what happens if you overwrite it while execution, might work as well)

document.getElementById("player-name").innerHTML = sessionStorage.getItem('player');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top