Last active
August 29, 2015 14:01
-
-
Save kylewelsby/d86adf51be1a69b36ad0 to your computer and use it in GitHub Desktop.
useful function to get an HTML Element detail as an object.
This file contains 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
window.HTMLElementDetail = function(elm) { | |
var rect = elm.getBoundingClientRect(), | |
style = window.getComputedStyle(elm, null); | |
return { | |
textContent: elm.textContent || elm.innerText, | |
selector: document.generateSelector([elm]), | |
css: { | |
top: (rect.top + window.scrollY) + 'px', | |
left: (rect.left + window.scrollX) + 'px', | |
//right: rect.right + 'px', | |
//bottom: rect.bottom + 'px', | |
width: rect.width + 'px', | |
height: rect.height + 'px', | |
fontSize: style.getPropertyValue('font-size'), | |
fontFamily: style.getPropertyValue('font-family'), | |
fontStyle: style.getPropertyValue('font-style'), | |
fontWeight: style.getPropertyValue('font-weight'), | |
fontVariant: style.getPropertyValue('font-variant'), | |
textAlign: style.getPropertyValue('text-align').replace('-webkit-', ''), | |
lineHeight: style.getPropertyValue('line-height'), | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment