How to change button color, highlited color, etc. ?

I need script for changing colors of buttons. I tried https://docs.unity3d.com/ScriptReference/UI.ColorBlock.html to change color of button, but it doesn’t work for me. Is there another way how to use it?

Here is a script you have to attach to the gameobject you want (preferably the button):

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class CustomButton : MonoBehaviour {

    public Button button ; // Drag & Drop the button in the inspector
	
	public void TurnRed()
	{
		ColorBlock colors = button.colors;
		colors.normalColor = Color.red;
		colros.highlightedColor = new Color32(255, 100, 100, 255);
		buttons.colors = colors;
	}
	
	public void TurnWhite()
	{
		ColorBlock colors = button.colors;
		colors.normalColor = Color.white;
		colros.highlightedColor = new Color32(225, 225, 225, 255);
		buttons.colors = colors;
	}
}

I used this:
public void TaskOnClick1()
{
GameObject buttonclr = GameObject.Find(“Button1”);
buttonclr.GetComponent().color = Color.magenta;
buttonclr.GetComponent().highlightedColor= Color.blue;
}
You have to find the button with you want to work with, so instead of “Button1” put the name of your button
After that, you have to assign the void to the button