Workaround for dealing with custom attributes not getting copied using cloneNode Certain occasions when you have a few local attributes on an element that you want to keep around Of course you don t want to do each one manually So you can add in an extra check to detect any custom ones local to the element and copy them after let div document createElement div let span document createElement span div appendChild span add some local attributes custom things to remember div att1 cat div att2 22 var clonediv div cloneNode true copies fine but excludes the custom small fix extra to include custom extra attributes in base let atts div attributes for let key in div if div hasOwnProperty key false continue clonediv key div key debug print out which custom ones were manually copied console log key hasOwnProperty div hasOwnProperty key console log done
things to remember div att1 cat div att2 22 var clonediv div cloneNode true copies fine but excludes the custom small fix extra to include custom extra attributes in base let atts div attributes for let key in div if div hasOwnProperty key false continue clonediv key div key debug print out which custom ones were manually copied console log key hasOwnProperty div hasOwnProperty key console log done