I am cloning an element and removing the id to avoid duplicates. Typically there will only be a class. In the event an end user chooses to use an id and style it, I want to ensure the style is preserved on the cloned element. Here is a rudimentary example.
/* css */
#unique {
background: yellow;
}
.general {
border: 1px solid blue;
}
/* html */
<div id="container">
<div id="unique" class="general">hello</div>
</div>
/* js/jquery */
$(function() {
$( ".general" ).clone().appendTo( "#container" ).removeAttr( "id" );
});
EDIT: The linked duplicate provides a jQuery plugin solution. It uses .getComputedStyle method which works but is resource intensive since it loads all of the computed styles. I was hoping for a way to identify only the end user's couple of styles that they may have applied to an id.