Interactions Need to Be Able to Alternate Attribute Values

Currently, the Interactions feature can toggle an attribute on or off, but it can’t swap values.

Simple example:

click = aria-expanded=true
click again = aria-expanded=false

This is very limiting.

15 Likes

Would be nifty to be able to manipulate interactions like this. How do we “upvote” this request?

Just “like” to upvote!

1 Like

My work here is done - thanks.

I had the same problem above the topic.
I used the Action: JavaScript (Function).

And, I put the below code into the Wordpress admin page > Bricks > Settings > Custom Code > Header scripts

<script>
function toggleChangeAriaExpanded(targetId) {
   // console.log("targetId.targets[0]", targetId.targets[0]);

    // Get the button element
    const buttonElement = targetId.targets[0];

    // Check the value of the aria-expanded attribute of the button element
    const ariaExpanded = buttonElement.getAttribute('aria-expanded');

    // Check if aria-expanded is "true"
     if (ariaExpanded === "true") {
       // If the button is found, change the aria-expanded attribute
      buttonElement.setAttribute("aria-expanded", "false");
    //  console.log(buttonElement);
     } 
  //else {
       //console.log("The button cannot be found or aria-expanded is not true.");
    // }
}
</script>