Skip to content
Advertisement

Change aria attribute value using JavaScript Observer method

Can someone provide me with an example of an HTML div element with an attribute of aria-highlight that changes and notifies the element using the JavaScript observer method? An example would be using a checkbox that toggles the div and changes the background of the div element. I need this done in vanilla JavaScript

Example HTML

JavaScript

Advertisement

Answer

So below, you have a checkbox with an event handler to toggle the aria-highlight value.

And an observer which triggers on attribute change from the div.

JavaScript
JavaScript
Advertisement