javascript - dataset property doesn't work with objects? -
el2.dataset.stuff = document.getelementbyid('el1');
doesn't seem work.
i need able access innerhtml property of el1, later.
el2.dataset.stuff = document.getelementbyid('el1').innerhtml;
works, don't idea of storing duplicate content in variables. if have many elements, eat lot of memory.
i guess because dataset requires strings? if that's true, how set reference elmement inside el2 ?
actually can store strings in dataset
attributes definition.
so in case either should have separate data-structure (which should accessible in both needed scopes) store reference this:
var mypointers = { 'el2': { 'stuff': document.getelementbyid('el1') } }; // later var el1 = mypointers.el2.stuff;
or store id of el1
, retrieve actual element, when needed:
el2.dataset.stuff = 'el1'; // later var el1 = document.getelementbyid( el2.dataset.stuff );
Comments
Post a Comment