If you're looking for a way to track down and debug style modifications in the DOM, one possible method is to utilize a DOM breakpoint within Chrome Dev Tools
To make this approach effective, it's important to set the breakpoint before the style changes are implemented. While this may be challenging at times, you can force a breakpoint to occur prior to any JavaScript loading by inserting the following code right after the relevant HTML element:
<script>debugger</script>
Here's how you can test it out with the provided code snippet:
- Click on the "Run Code Snippet" button located below
- Access Dev Tools from your browser
- Right-click on the designated paragraph element
- Choose Break On... -> Attribute modifications from the context menu
- Click on the "Add border color" button as indicated
- Observe the debugger in action as it halts at the script responsible for the style alteration
window.onload = function() {
document.querySelector('button').addEventListener('click', function() {
document.querySelector('p').style.border = '2px solid red';
});
}
<p> Sample Paragraph </p>
<button>Add border color</button>