Muditā (co-joy, recognition) is a central concept in Buddhist mind training and ethics. Muditā is part of the Four Immeasurables (Appamaññā) - also called the "Four Divine Abiding States" (Brahmavihara).
Compassionate joy is essentially aimed at rejoicing oneself with other beings for their attained well-being and wishing them not to lose that well-being again.
In the same way, for example, Karunā, compassion, aims at truly understanding the existing suffering of others and, on the basis of mutual identification, remembering or sympathizing with others in awareness of interdependence.
The consequence of this compassion (thinking) is then the wish that that other being may be freed from its suffering, free itself from suffering. Thus, while Karunā is the wish for beings to be liberated from suffering, Muditā is the wish for the attainment and maintenance of a suffering-free state of well-being.
What causes this well-being does not matter at first, as long as this well-being is not based on the harm of others and is not visibly to the detriment of the one who enjoys it.
Above all, it is necessary to understand that something that makes another person happy does not have to be the same thing that makes oneself happy. So you have to step back from your own ideas and try to really understand and empathize with the other person's joy - to empathize.
The opposite of compassionate joy is envy (issā). This is a karmically unwholesome (akusala) mind factor, described in the Abhidhamma as belonging to the hateful mind formations (cf. greed, hatred and delusion as the three mind poisons). More difficult for the practitioner to recognize than this opposite state of mind is the near enemy of fellow joy, worldly glee, pleasure.
In his commentary on the Tipitaka, the Visuddhimagga (Way to Purity), Buddhaghosa summarizes compassionate joy:
"The characteristic of compassionate joy consists in rejoicing [with beings], its essence in non-benevolence, its expression in displacement of displeasure, its basis in recognition of the state of happiness of beings, its success in abolition of displeasure, its aberration in the arising of pleasure." (Vis.IX.5)
The unfolding of compassionate joy (muditā-bhāvanā) is again described in more detail by Buddhagosa (Vis.IX.3 and Vis.IX.5); the section below follows this account:
"First, one should think of the object of fellow joy as a very dear friend. One who is thoroughly filled with joy. One should rejoice in his fulfilled state and thus direct one's co-joy towards him. You should think and feel something like this: 'Oh, how happy this being is. How beautiful it is!'-a sensation of joy such as one has at the sight of a dear person."
"It is unsuitable for the beginner in the practice of active co-joy to choose as an object a beloved, an indifferent or even a hostile person. In the case of the beloved, there will most likely be more desire than joy in the sense of Muditā, the person one is indifferent to will be indifferent, and in the case of the enemy, aversion or even hatred will more likely arise in one.
Above all, however, extreme desire and hatred are unwholesome states of mind that do not contribute to the cultivation of the brahmavihara, compassion (muditā), compassion (karunā), equanimity (upekkhā), and loving-kindness (mettā)."
"Now, once one has managed to feel compassionate joy with regard to one's dear friend, extend this practice to those indifferent to oneself and to one's enemies.
Only when one has been fully successful here again, one should include other persons and beings. For example, one might extend compassionate joy first to one's family, then to all one's friends, all one's neighbors, the whole town, etc., until finally compassionate joy excludes no being."
In the subculture of polyamory, there is a similar form of fellow-joy that is expressed in joy that a loved one is loved by someone else and feels happiness. The term compersion exists for this "opposite of jealousy."