HTMLElement offsetParent is undefined
See original GitHub issueI have some code depending upon an HTMLElement’s offsetParent, specifically within an event listener. Code I have here:
window.addEventListener('mousemove', function(e) {
const control = e.target.offsetParent;
if (!control) {
return;
}
const factor = this.state.duration / control.offsetWidth;
const time = e.pageX * factor;
actions.setCurrentTime(time);
});
However, when I test this with jest (and therefore JSDOM), I can’t seem to get offsetParent
to be defined in any way.
Is this an unsupported attribute of an HTMLElement?
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
HTMLElement.offsetParent - Web APIs | MDN
The HTMLElement.offsetParent read-only property returns a reference to the element which is the closest (nearest in the containment hierarchy) ...
Read more >What would make offsetParent null?
offsetParent will return null if your element object hasn't been appended to the DOM yet.
Read more >HTML DOM Element offsetParent Property
The offsetParent property returns null if the element is not visible (display="none"). Tutorial: CSS Box Model. The offsetParent. All block-level elements ...
Read more >Google Groups
offsetParent /offsetTop/offsetLeft/offsetWidth/offsetHeight. 1058 views ... In Gecko and Edge, these attributes are only supported on HTMLElement.
Read more >Lightning SecureElement should return null instead of undefined as ...
HTMLElement.offsetParent returns null if no other answer can be found, however Locker Services SecureElement.offsetParent returns undefined.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I know this is old but if someone ever find this and has trouble, I got around it doing something similar to above:
@panganibanpj Thanks for the code snipped. I enhanced it with some of the mozilla specs.