Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

append to a div and save the previous data after refresh page in javascript

<!doctype html>
<html>
<head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js">
</script>
</head>
<body>
<div style="width:10em; height:10em; border-style:solid; border-color:black;" id="editor1" contenteditable="true"></div>
<button id="savebtn">Save Changes</button>
<div style="width:10em; height:5em; border-style:solid; border-color:red;" id="Contentable"></div>
<script>
    var editElem = document.getElementById("editor1");
    $(document).ready(function() {
      $("#savebtn").click(function() {
        var title = prompt("What would you like your title to be?");
        localStorage.setItem(title, editElem.innerHTML);
        titles = localStorage.getItem("titles");

        if (titles == null) {
          titles = [];
        } else {
          titles = JSON.parse(titles);
        }
        titles.push(title);
        localStorage.setItem("titles", JSON.stringify(titles));
        var htmlData = "<a onclick=showData('" + title + "')>" + title + "</a><br>";
        $("#Contentable").append(htmlData);
        var userVersion = editElem.innerHTML;
        localStorage.setItem("userEdits", userVersion);
        editElem.innerHTML = "";
      });
    });

    function showData(txt) {
      editElem.innerHTML = localStorage.getItem(txt);
    }
</script>
</body>
</html>
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to get value from a label in javascript gtk 
Javascript :: Make an array from the HTML Collection to make it iterable 
Javascript :: jquery ui music player 
Javascript :: to see all function attribute and methods in javascript 
Javascript :: c program to print triangle using recursion in javascript 
Javascript :: wakatime cli installation via npm 
Javascript :: code mirror get value from dom 
Javascript :: math library javascript 
Javascript :: React Hook "useState" is called in function "app" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter 
Javascript :: playwrigth await browser 
Javascript :: Get physical path in javascript 
Javascript :: how to get the folder of the extension 
Javascript :: p5 js stop video camera capture 
Javascript :: custom validator Whitelisting 
Javascript :: req.parms en react js 
Javascript :: serverless web app with react netlify 
Javascript :: SuiteScript https.post a pdf file 
Javascript :: Example of Private Class Methods and Accessors in es12 
Javascript :: how to change sender name in nodemailer 
Javascript :: format file using jq 
Javascript :: red foreach loop 
Javascript :: maxscript create new Layer 
Javascript :: delayed usestate double click 
Javascript :: jsx tag with children react js 
Javascript :: redirect to login when session expires jsf 
Javascript :: Javascript - The file size is measured in bytes 
Javascript :: Refresh a kendo ui widget, when options on AngularJS $scope change 
Javascript :: vue js key modifiers 
Javascript :: how to call AWS Serverless api in Node/JS 
Javascript :: Spread Syntax for array literals or strings 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =