how to check presence of sprite on a UI button?

I want to check , if sprite is present on the clicked button or not , and if present then take that sprite in a gameobject for accessing it.

I haven’t tested the following code, but give it a try :

First of all, put this at the top of your file :

using UnityEngine.EventSystems;

Then, in the function called by the onClick callback of your button :

public void OnButtonClicked()
    GameObject clickedButtonGameObject = EventSystem.current.currentSelectedGameObject ;
    Button button = clickedButtonGameObject.GetComponent<Button>();
    Image image = button.targetGraphic as Image;
    if( image != null )
        Sprite sprite = image.sprite ;
        Debug.Log( sprite ) ;