Created
July 27, 2023 17:54
-
-
Save shishirraven/b170dab057eb95b0f38fb824aee64fd1 to your computer and use it in GitHub Desktop.
Getting the Sections
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
function highlightElements() { | |
const pageWidth = document.body.clientWidth; | |
const styleTag = document.createElement('style'); | |
styleTag.innerHTML = ` | |
.highlight { | |
border: 2px solid red; | |
background-color: yellow; | |
} | |
`; | |
document.head.appendChild(styleTag); | |
const allElements = document.querySelectorAll('*'); | |
allElements.forEach(element => { | |
const widthPercentage = (element.clientWidth / pageWidth) * 100; | |
const height = element.clientHeight; | |
const parent = element.parentElement; | |
if (widthPercentage > 95 && height > 200 && height < 900 ) { | |
console.log(widthPercentage,height,parent) | |
} | |
if (widthPercentage > 95 && (height > 200 && height < 900)) { | |
element.classList.add('highlight'); | |
} | |
}); | |
} | |
highlightElements(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment