I initially thought a regex to remove YUI3 classNames (or whole class attributes) and id attributes from a serialized DOM string was a sound enough approach - but now I'm not sure, given various warnings about using regex on HTML.
I'm toying with the idea of making a copy of the DOM structure in question, performing:
var nodeStructure = Y.one('#wrap').all('*'); // A YUI3 NodeList
// Remove unwanted classNames.. I'd need to maintain a list of them to remove :/
nodeStructure.removeClass('unwantedClassName');
and then:
// I believe this can be done on a NodeList collection...
nodeStructure.removeAttribute('id');
I'm not quite sure about what I'd need to do to 'copy' a collection of Nodes anyway, as I don't actually want to do the above to my living markup, as its only being saved - not 'closed' or 'exited', a user could continue to change the markup, and then save again. The above doesn't make a copy, I know.
Is this efficient? Is there a better way to 'sanitize' my live markup of framework additions to the DOM (and maybe other things too at a later point), before saving it as a string? If it is a good approach, what's a safe way to go about copying my collection of Nodes for safe cleaning?
Thanks! d
(This is the regex-related post on my first idea to clean up the serialized entire DOM structure: Safe regexs to clean serialized DOM?, that question contains some sample HTML, if you want it)
"I'm not quite sure about what I'd need to do to 'copy' a collection of Nodes" Yi Jiang, you never came back :( Just answering this Q for completeness.