How would you change a attribute value when you're trying to initially set the attribute to a variable:
<div class="random" aria-expanded="false">
...
</div>
// setting the attribute value to variable `getAttrValue`
var getAttrValue = $('.random').attr("aria-expanded");
if ( getAttrValue == "false" ) {
// try to set the aria-expanded to true
} else {
// try to set the aria-expanded to false
}
I can do it like this:
if ( getAttrValue == false ) {
$('.random').attr("aria-expanded", "true");
} else {
$('.random').attr("aria-expanded", "false");
}
But I was trying to see if I can utilize the variable and shorten the coding