I am looking to identify changes in CSS properties without needing the actual values. I only require the specific style property that has been altered. For example, I need the style property to be stored in a variable, as shown below:
document.getElementById('id1').style.backgroundColor = 'red';
document.getElementById('id1').style.color = 'red';
I have attempted using a MutationObserver with a style filter, but I am exploring other potential methods to retrieve the style property.
<h1 id="id1" style="background-color:green;color:blue;">My Heading 1</h1>
<button type="button"
onclick="document.getElementById('id1').style.color = 'yellow'">
Click Me!</button>
<button type="button"
onclick="document.getElementById('id1').style.backgroundColor = 'red'">
Click Me!</button>
const Observep = document.getElementById("id1");
const observerp = new MutationObserver(function() {
// var styleproperty = (backgroundColor or color or width....)
alert("id1 change" + styleproperty);
});
observerp.observe(Observep, {subtree: true, attributes: true});