Skip to content

Instantly share code, notes, and snippets.

@shaal
Created January 6, 2023 20:05
Show Gist options
  • Save shaal/ac462ba64185b43df8063ca606ee491f to your computer and use it in GitHub Desktop.
Save shaal/ac462ba64185b43df8063ca606ee491f to your computer and use it in GitHub Desktop.
toggle outline styles on all custom elements (without shadow-dom scan)
// 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