Note that there are some explanatory texts on larger screens.

plurals
  1. POStorage and retrieval of DOM element
    primarykey
    data
    text
    <p>Wondering if anyone out there has ran into this before....</p> <p>I'd like to use JavaScript to identify a DOM element on a page, then store it's reference in a database or cookie for later retrieval. </p> <p>To get specific, what I'm looking to do is create a UI so that when the user CLICKs an element on a page, JavaScript fires the click event, passing the instance of the DOM element clicked on. </p> <p>easy so far, right?</p> <p>So what I want to do is store the "identity" of this DOM element, say in a database, so when I later return to this page, I can pull out all stored DOM element identities and get access to them in the page once more.</p> <p>So this is quite simple if this DOM element has a unique ID. Just store the ID, then when the page comes back up, we just do a getElementByID and we've got our DOM element again.</p> <p>The problem is that not everything in the DOM has a unique identifier, so there the problem lies.</p> <p>I had some bad ideas initially, like iterating through the entire DOM and incrementing them with unique class names (dom-01, dom-02, etc) and this would give me an identifier. But this would cause a lot of initial overhead and if the page ever changed, the order of the DOM elements wouldn't be the same, so we wouldn't get back the correct DOM elemet.</p> <p>I'mve never tried it, but another thought was to serialize the DOM element, stick it in the DB, and then on reload parse to an object, and use that object to find my original DOM element. I've never done that before, so how I can actually compare the restored (parsed) object to the one in the DOM is a big unknown.</p> <p>Specifics on the serialization solution or any other original ideas for accomplishing this are welcome!!</p> <p>Thanks in advance everyone!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload