Skip to content

Commit 2ee4ecc

Browse files
Add functionality to change html after DOM creation
1 parent a4effec commit 2ee4ecc

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

_static/overlay-label-accessibility.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
document.addEventListener('DOMContentLoaded', function() {
1+
function fixAccessibility() {
22
// Fix overlay <label> elements by replacing them with <div>
33
document.querySelectorAll('label.overlay').forEach(function(label) {
44
var div = document.createElement('div');
@@ -25,8 +25,10 @@ document.addEventListener('DOMContentLoaded', function() {
2525
});
2626

2727
// Inject CSS for .sr-only (optional, in case you use it elsewhere)
28-
var style = document.createElement('style');
29-
style.innerHTML = `
28+
if (!document.getElementById('sr-only-style')) {
29+
var style = document.createElement('style');
30+
style.id = 'sr-only-style';
31+
style.innerHTML = `
3032
.sr-only {
3133
position: absolute !important;
3234
width: 1px !important;
@@ -39,5 +41,15 @@ document.addEventListener('DOMContentLoaded', function() {
3941
white-space: nowrap !important;
4042
}
4143
`;
42-
document.head.appendChild(style);
44+
document.head.appendChild(style);
45+
}
46+
}
47+
48+
// Run once at DOMContentLoaded (for static content)
49+
document.addEventListener('DOMContentLoaded', fixAccessibility);
50+
51+
// Also run when new nodes are added (for dynamic content)
52+
const observer = new MutationObserver(function(mutationsList, observer) {
53+
fixAccessibility();
4354
});
55+
observer.observe(document.body, { childList: true, subtree: true });

0 commit comments

Comments
 (0)