How to Inspect Dynamic HTML Elements (that keep disappearing!) in Chrome

I still find styling HTML elements difficult at times, trying to figure out where the styling is being inherited from and exactly which elements I need to apply styles to. The Developer Tools in Chrome go a long way to assisting with this. For this tip I’ll assume you are familiar with Chrome Developer Tools for inspecting HTML elements and CSS styles.

What I wanted to focus on was those frustrating elements that only exist on the page (in the Document Object Model) while a certain element has the “focus”. This often happens with navigation menu options or dropdown controls, where you have the menu options or dropdown options visible on the screen but as soon as you click something in Developer Tools (to go exploring), the menu options or dropdown options disappear and don’t exist on the page anymore! This is usually because an event such as the blur event is fired when you click outside the element and this removes the elements from the page that you are trying to inspect.

This tip might not work in all scenarios but it has gotten me out of trouble on a few occasions.

Here’s an example scenario. On the left side of the screenshots you can see the OnePlaceMail (Outlook Add-in) displayed in Chrome, on the right hand side is Developer Tools inspector window. I’m using a 3rd party control for my “Content Type” dropdown (it’s the Kendo UI for Angular library)

When collapsed it’s easy to inspect the kendo-dropdownlist element (that holds the selected value of ‘Document’. At this stage the menu options that will appear when I click on the dropdown don’t even exist in the DOM.

css-dynamic-inspection-chrome-cameron-dwyer-01-kendo-dropdown

When I do click to expand the dropdown, the image below shows that a new kendo-popup element appears in the DOM (and it contains sub-elements to represent each of the options). But the problem is if we now try to use the Developer Tools and expand that kendo-popup element to see those sub-elements then the dropdown collapses (because I’ve click off it) and the kendo-popup element is removed from the DOM and we’re left with nothing to inspect!

css-dynamic-inspection-chrome-cameron-dwyer-03-kendo-dropdown-expanded

So to work around this in the Developer Tools inspector, right click on the element that is driving the elements to appear/disappear (kendo-dropdownlist) and select Break on | subtree modifications.

css-dynamic-inspection-chrome-cameron-dwyer-06-break-on-subtree-modifications

Now go to the web page and click on the dropdown to show the dropdown options. They are shown (elements added to the DOM) but the Developer Tools inspector now goes into a paused state. The web page is effectively frozen.

css-dynamic-inspection-chrome-cameron-dwyer-07-break-on-subtree-modifications-paused

While in this paused state, you can now return to the elements tab and we can expand and explore that pesky kendo-popup element that was dynamically created. This time however the dropdown won’t collapse itself as we click around in the inspector.

css-dynamic-inspection-chrome-cameron-dwyer-08-break-on-subtree-modifications-paused-stays-expanded

I hope you find this tip useful

 

Advertisement

8 thoughts on “How to Inspect Dynamic HTML Elements (that keep disappearing!) in Chrome

Add yours

  1. Thank you very much, I’m really grateful as I’m not a professional programmer and I have literally spent over two days attempting many a work around to get this right.
    Kind regards from Spain

    Liked by 1 person

  2. Thanks a lot, exactly what I needed. Well actually I needed not subtree but attribute modifications for tracking changes in my element and not in its children. Anyway, much appreciated.

    Liked by 1 person

  3. I was trying to look at the CSS for the top navigation drop down menu items in a SharePoint site.

    The trick that worked for me is to right click on the menu item and choose Inspect. Then, right click again. While the right-click menu is displayed, move your mouse off the page and into the dev tools. You can then hit the escape key to hide the right-click menu, or click on any element in the DOM.

    You should now be able to use the Elements tab to explore the styles and DOM, as long as you don’t move your mouse back onto the page. Basically you are preventing the page receiving any mouse events while the right-click menu is shown.

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: