Changing Button Image On Click (Javascript)

Exactly what the title says. I have tried looking it up but nothing seems to work. The last thing I tried was:

     if(BID == 1){
         B1.GetComponent.<Image>() = CubeButton;

Which gives the error: Assets/Inventory.js(96,41): BCE0049: Expression ‘self.B1.GetComponentof UnityEngine.UI.Image’ cannot be assigned to.

I am just trying to change the button image to an image of a cube when I click on it.

You’re trying to set the instance of component, which won’t work. You should change its sprite with Image.sprite.
https://docs.unity3d.com/ScriptReference/UI.Image-sprite.html