Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shishirraven/b170dab057eb95b0f38fb824aee64fd1 to your computer and use it in GitHub Desktop.
Save shishirraven/b170dab057eb95b0f38fb824aee64fd1 to your computer and use it in GitHub Desktop.
Getting the Sections
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