How to switch classes in Blazor on button click?
P粉041881924
P粉041881924 2024-03-28 00:07:37
0
1
585

I currently have an onclick event that switches classes like this:

....
<button id="@m.TargetCo.ButtonId" onclick="glyphChanger(this.id)" class="btn btn-default iconButton glyphicon glyphicon-chevron-right" ></button>
....
function glyphChanger(buttonID) {
    $("#" + buttonID).toggleClass('glyphicon-chevron-right glyphicon-chevron-up');
}

P粉041881924
P粉041881924

reply all(1)
P粉269847997

No JavaScript required. You can do this the Blazor way.

DropDownComponent.razor

Debug: @buttonCss

@code { private string buttonCss = "glyphicon-chevron-right"; private void ChangeButtonClass() { buttonCss = buttonCss == "glyphicon-chevron-right" ? "glyphicon-chevron-up" : "glyphicon-chevron-right"; } }

Elsewhere in the app




Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template