Skip to content

Instantly share code, notes, and snippets.

@robertknight
Last active Aug 31, 2016
Embed
What would you like to do?
Safari 9.x Element.dataset corruption investigation
<html>
<body>
<div id="root" data-ref="searchBucket">
<div>
<div data-ref="header">
<div></div>
<div></div>
</div>
<div data-ref="content">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
</div>
<script src="site.js"></script>
</body>
</html>
function findRefs(el) {
var map = {};
if (el.dataset.ref) {
map[el.dataset.ref] = el;
}
var node;
for (var i=0; i < el.children.length; i++) {
node = el.children[i];
Object.assign(map, findRefs(node));
}
return map;
}
var searchEl = document.getElementById('root');
findRefs(searchEl);
findRefs(searchEl);
var refs = findRefs(searchEl);
var result = document.createElement('div');
result.textContent = Object.keys(refs);
document.body.appendChild(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment