-
-
Save wplit/7861b18ef34ffd955b43ddcacc9ef6e8 to your computer and use it in GitHub Desktop.
jQuery(".oxy-dynamic-list").find("*").removeAttr('id'); |
Note; there's likely a better solution (better in terms of jQuery performance) but I haven't time now to go into it.
Related if anybody wants to give it a go : https://stackoverflow.com/questions/482763/jquery-to-check-for-duplicate-ids-in-a-dom
This performs much faster.. Note; this will not remove the first instance of the ID found, only the duplicates of that ID found further down the page. So the first stays in the html the 2nd, 3rd, 4th... just the duplicates are removed. This is because when it finds the first one, it doesn't yet know it has duplicates and it only runs once down the page, when it finds the 2nd one, it removes it and so on... The previous code, above, removes all IDs that have duplicates, even the very first one, but it's slower to run.
(function($){
//abort if we're viewing inside builder
if ($ ('html'). attr ('ng-app') == 'CTFrontendBuilder')
return;
var ids = {};
$('.oxygen-body [id]').each(function() {
if (this.id && ids[this.id]) {
$(this).removeAttr('id');
}
ids[this.id] = 1;
});
})(jQuery);
I do hope there is some way Oxygen can build an option to disable all ID's on the front end. Or at least turn them into classes if they need to be there. Would solve all these problems in one go.
Yeah, let's see what they figure out here since we run into the same issue over and over again. Would be great to move over to classes let user utilize ID for other purposes such as jump/anchor links.
Thanks, I'll give it a run later on!
It's not possible to do this in php to not even render specific block ID's in the frontend. Thinking about this being more suitable for performance than manipulate with jQuery. If possible.
Many workarounds in inline js now, think I will be about time to enqueue a static file so be can utilize caching.
woah, I didn't know about the Gutenberg duplicate ID problem. Oh boy, this will get messy.
Something like this would work to search through the whole html and find only the id's that are duplicated, then remove the id attribute for those elements only..
I do hope there is some way Oxygen can build an option to disable all ID's on the front end. Or at least turn them into classes if they need to be there. Would solve all these problems in one go.