Last active
February 17, 2022 23:30
-
-
Save michventura/ec2dcaeba962d3858b9793eca3e04927 to your computer and use it in GitHub Desktop.
Script para dar clic en elementos y mostrar su propiedad de display
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
document.addEventListener('DOMContentLoaded', () => { | |
function getDisplayValue(element) { | |
let displayValue = window.getComputedStyle(element.target).display | |
return displayValue | |
} | |
document.body.querySelectorAll('*').forEach(element => | |
element.addEventListener('click', e => { | |
let value = getDisplayValue(e) | |
if (value === 'inline') { | |
e.target.classList.toggle('outlineInline') | |
} | |
if (value === 'block') { | |
e.target.classList.toggle('outlineBlock') | |
} | |
if (value === 'flex') { | |
e.target.classList.toggle('outlineFlex') | |
} | |
if (value === 'grid') { | |
e.target.classList.toggle('outlineGrid') | |
} | |
e.stopPropagation() | |
}), | |
) | |
let notes = document.createElement('div') | |
notes.classList.add('notes') | |
notes.innerHTML = `<ul> | |
<li data-display="inline">inline</li> | |
<li data-display="block">block</li> | |
<li data-display="flex">flex</li> | |
<li data-display="grid">grid</li> | |
</ul>` | |
document.body.appendChild(notes) | |
notes.addEventListener('click', e => { | |
let child = e.currentTarget.children[0] | |
console.dir(child) | |
child.classList.toggle('sr-only') | |
e.stopPropagation() | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment