| title | Inspect the ninja element available on hover or focus | ||
|---|---|---|---|
| description | Three ways to debug some element that is displayed on hover or focus. | ||
| cover | images/cover.png | ||
| date | 2021-12-09 | ||
| dateUpdated | Last Modified | ||
| tags |
|
{% import "macros.njk" as macros with context %}
Sometimes you have a task to debug some element that is displayed on hover or focus. But it hides when clicked outside the viewport. For example, when you click somewhere in DevTools.
So, how to debug such ninja elements? Let’s use Chrome DevTools possibilities for that.
The most general solution is to choose :hover state in the Toggle Element State panel.
Let’s see it in action.
{{ macros.video('./images/netlify@1440', 1440, 900, true, false) }} Just use `:hover` toggler.Unfortunately, in many cases, enabling pseudo-classes is not enough.
For pages that use JavaScript to toggle a focused state you can try to emulate focus on a page. Did you know that you can call a Command Menu with Ctrl Shift P (⌘ ⇧ P for macOS)? It has a command Emulate a focused page that can help us with our issue.
Let's see it in action.
{{ macros.video('./images/yandex@1440', 1440, 900, true, false) }} Perfect case!In some very strange cases, the hover state is set with JavaScript. And it is difficult to debug such cases because JS doesn’t handle a focus state. But we have a “hammer” for that.
{{ macros.img('./images/break-on.png', '"Break on..." menu in DevTools.') }} Right Click on a DOM-element, Break on..., attribute modifications.When the class attribute of the element is changed, we’ll have a JavaScript breakpoint triggered.
Let’s see it in action.
{{ macros.video('./images/amazon@1440', 1440, 900, true, false) }} The debugger freezes the page, so you can easily inspect all the elements.