Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get whole element, innerHTML gets only inner part?

I have a function that gets the product and the id of this product, I need to put the entire HTML into local storage, I try it like this, but the innerHTML gets only the inner part, please tell me how to fix it?

function storagePlusQuantity(product, productId) {
    const storageId = 'product' + productId;
    localStorage.removeItem(storageId);
    localStorage.setItem(storageId, product);

    console.log(product)

}

The photo shows an example of the product of which I receive a functionenter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you have code like this:

<div id="outer-div">
~~something~~
</div>

getting the innerHTML of the div will only get the ~~something~~ part.

What you want to do is just get the div with outerHTML.

See codepen example: See Codepen Here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading