Help on how to use setItem and getItem of localStorage

0

I'm trying to save an answer, but I can not, every time I refresh the previous answer back. Here's what I'm trying to implement:

<!DOCTYPE html>
<html lang="pt-BR">
    <head>
        <meta charset="utf-8">
        <title>question and answer</title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script><style></style></head><body><p>WhatisthecapitalofBrazil?</p><pid="resposta">
        Rio de Janeiro   
        </p>

    <script>
        $(function () {
            $("p").dblclick(function () {
                var conteudoOriginal = $(this).text();

                $(this).addClass("respostaEmEdicao");
                $(this).html("<input type='text' value='" + conteudoOriginal + "' />");
                $(this).children().first().focus();

                $(this).children().first().keypress(function (e) {
                    if (e.which == 13) {
                        var novoConteudo = $(this).val();
                        $(this).parent().text(novoConteudo);
                        localStorage.content = $('#resposta').html();
                        $('#resposta').html(localStorage.content);
                        $(this).parent().removeClass("respostaEmEdicao");
                    }  
                });


            $(this).children().first().blur(function(){
                $(this).parent().text(conteudoOriginal);
                $(this).parent().removeClass("celulaEmEdicao");
            });
            });

        });
    </script>

    </body>

</html> 

What am I doing wrong?

    
asked by anonymous 01.08.2018 / 17:59

1 answer

2

Try this:

First you put your data in the localStorage and name it:

localStorage.setItem('Content', $('#resposta').html());

Then you get it in the localStorage by the name you put:

$('#resposta').html(localStorage.getItem('Content'));

This will return the value you assigned.

I hope I have helped

    
01.08.2018 / 18:09