'Remove ID from Dom if empty in Oxygen Builder

This is a development question, and any help is much appreciated. Here goes...

I know it's possible to remove all the ID's in Oxygen with this js input;

jQuery('body:not(.oxygen-builder-body) *').removeAttr('id');

But is it possible to change this so that all ID's will be removed except for all the ID's with a prefix For example: id="prefix-idname".

Example id in Oxygen builder below. I can remove this, but the result is that the ID is still in the Dom. See below.

id still in dom even when removed

As you can see below in the source code, the ID is empty but the prefix is still there in the Dom. I want this to be removed, keeping the class only.

id is not removed from dom

The final output would be: <section class="ct-section-slider"....</section>..

This process needs to be revered as well. So If the ID starts with a prefix-idname in Oxygen Builders id field, the ID will not be removed. This needs to apply to all nested div's that might be under the main div .

The final output would be: <section id="section-2-5" class="ct-section-slider"....</section>..

Why do I want this? I just want a clean HTML source, because usually we get empty ID's and don't use them in Oxygen Builder.

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source