For some reason when I try to call
renderer.enabled = false;
You can use
GetComponent<Renderer>().enabled = false; to disable the GameObject's Renderer component. This will mean the Renderer simply does not render the GameObject. Unity docs for
Alternatively, if you want to make the UI element invisible you could add a Canvas Group component to it and set the Alpha channel to 0. This makes the element (and any of its children) 100% transparent.