index.tsx441 chars15 lines
Explanation:
document.querySelectorAll
to select all elements without a data-key
attribute. We can filter the elements by using the attribute selector, :not([data-key])
. This returns a NodeList, which we convert to an array using the spread operator ...
.forEach
method to loop through each element in the array of elements without the data-key
attribute and remove them from the DOM using the remove()
method.data-key
attribute, and reappend them to the body using appendChild()
.gistlibby LogSnag