We can use JQuery to find the element and then we can replace the attribute value of an HTML element. Below is a JS code snippet to find and replace an attribute value.
$this.next().attr('aria-expanded', function(index, attr){
return attr == 'false' ? 'true' : 'false';
});