Music plays a significant role in human activities, with its dual role of functionality and entertainment. It exerts diverse influences on individuals. This study explores music’s impact on individuals’ moral cognition. To ensure the objectivity and accuracy of the findings, this study employed eye tracking as the research methodology. Participants were exposed to two distinct types of music: Rock music and Yayue, a serene and elegant form of traditional Chinese music. Participants were randomly assigned to either the Rock music group or the Chinese Yayue group. They were tasked with viewing images depicting moral and immoral behaviors while these two musical backgrounds played. The eye-tracking technology recorded participants’ gaze patterns, providing quantitative insights into their visual attention under different musical conditions. Our data analysis revealed that, in both groups, immoral images initially captured participants’ attention. However, participants exposed to Rock music focused more on immoral images, whereas those listening to traditional Chinese Yayue music significantly prioritized moral images. These findings contribute valuable new perspectives to the intersection of music and education research, shedding light on the dynamic relationship between music and moral cognition.