2

I have set a data to the javascript localstorage, i want to edit the data, which i am passing dynamic content . my code is

$(".table tr."+data_name+"").each(function(){
        countss++;
        selected.push("<table class='str"+countss+"' data-name='"+data_name+"' style='width:655px;'><tbody><tr><td>"+$(this).find('td').text()+"<span><input type='number' min='100' class='productQuantity quantityUpdate"+count+"' data-name='"+data_name+"' data-count='"+count+"' value='100' style='float:right;'/></span></td></tr></tbody></table>");
    });
    var values = selected.join('<br>');
    localStorage.setItem(data_name,values);

here i want to edit the data which is dynamic in the push data

anybody have idea to change the dynamic value ?

without extract the local storage html content?

Gireesh T
  • 77
  • 1
  • 2
  • 7
  • 1
    You just have to overwrite that `localStorage` key to a new value. Or, if you want to edit what's there, then you have no choice but to extract it, modify it and write it back. – Scott Marcus Apr 30 '18 at 13:46
  • Possible duplicate of [Storing Objects in HTML5 localStorage](https://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage) – Timir May 05 '18 at 04:32

1 Answers1

0

If you still have the values you can just update it and then localStorage.setItem again. If you dont you have to do localStorage.getItem(data_name) and then update, then localStorage.setItem again

You can almost view local storage as a type of database transaction.. It wont just update because you have updated the values var you actually have to persist the value by doing setItem

Jacques Ramsden
  • 801
  • 5
  • 20