-1

I am trying to update an HTML document from JavaScript.

    $('.L1.Class2').attr("name",'changed-text');
    $('input[value="1"].L1.Class2').parent().parent().parent().prev().html('changed-text');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr>
    <td>Change-this-text</td>
    <td><span><input class='L1 Class2' type="radio" name='Change-this-text' value=1></span></td>
    <td><span><input class='L1 Class2' type="radio" name='Change-this-text' value=0></span></td>
    <td><span><input class='L1 Class2' type="radio" name='Change-this-text' value=-1></span></td>
    </tr>

But this change is not persistent, whenever I refreshes the page, the change get reverted back to its original state. I want to make these changes persistent.

I tried searching on web and every other answer on StackOverflow suggests using loaclStorage for achieving same. But I don't want to load such data every time as it will increase run time.

Ashu
  • 2,066
  • 3
  • 19
  • 33
pandafy
  • 184
  • 13
  • https://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie – Zakaria Acharki Jul 30 '18 at 09:53
  • Whenever you refresh the page it will load without any knowledge of previous state. ___Unless___ you save that state to something like localstorage and query that `onload` – phuzi Jul 30 '18 at 09:53
  • You can't persistently change the DOM(Document Object Model) using javascript. What you are doing with jquery javascript is limited to runtime and will get back to original DOM on browser refresh – Om Sao Jul 30 '18 at 09:53
  • 1
    there is not an alternative. Javascript is for DOM manipulation on client side. Not for editing. You can do it with a server side technology if you fetch your data from a db – Lelio Faieta Jul 30 '18 at 09:53

1 Answers1

1

JavaScript only updates the values in the DOM, it won't change your HTML file. If you would like to make this to be persistent, you have to make the changes storing somewhere else then everytime you load this page again the values will be replaced in the correct DOM element. If you are not using localStorage on the browser, then you have to do this on the backend. If you want to keep using JavaScript, then you have to write it in node.js on the server.

Kwun Yeung
  • 130
  • 10