Created
January 6, 2023 20:05
-
-
Save shaal/ac462ba64185b43df8063ca606ee491f to your computer and use it in GitHub Desktop.
toggle outline styles on all custom elements (without shadow-dom scan)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get all elements | |
const elements = document.querySelectorAll('*') | |
// Create an array from elements | |
const elementArray = Array.from(elements) | |
// Map to node names | |
const nodeNames = elementArray.map(element => element.nodeName.toLowerCase()) | |
// Filter by which ones are registered | |
const allCustomElementNames = nodeNames.filter(customElements.get.bind(customElements)) | |
function toggleOutlineStyle() { | |
// loop through all custom elements and add outline style | |
allCustomElementNames.forEach(elementName => { | |
const elements = document.querySelectorAll(elementName) | |
elements.forEach(element => { | |
console.log(element) | |
if (element.style.outline === '') { | |
element.style.outline = "1px red dashed" | |
} else { | |
element.style.outline = '' | |
} | |
}) | |
}) | |
} | |
toggleOutlineStyle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment