0

So basically I'm trying to make a very simple add to cart button.

You click, you can continue "browsing" and when you click to go to the cart it will be there in the format I have it set up in.

I don't exactly need help with having it appear with the right text but mostly with cloning it and then appearing in a entirely different document.

I've tried cloneNode, but that simply appears on the same document.

If you know of any functions/way's to help that would help me a lot.

Moza
  • 3
  • 2
  • Unless your app is a SPA this is not going to work the way you think it will; state and DOM changes do not persist across page loads. Instead of trying to clone and persist the rendered HTML, keep the 'cart' selection data in localStorage, and have your Cart page read that local storage to see what people have selected. – Daniel Beck Oct 27 '21 at 19:57

1 Answers1

0

You can achieve this in many ways. From storing a value as a parameter in an URL, using localStorage, cookies, make your own state manager or use Redux, React Context API, MobX, etc.

Try with localStorage API.

localStorage.setItem('cartProduct', cartProduct)

then you can read it with

localStorage.getItem('cartProduct)

https://www.taniarascia.com/how-to-use-local-storage-with-javascript/