This question asserts that if we have a surface $M$, the diagonal $D \subseteq M\times M$ determines a cohomology class on $M \times M$. I'm trying to understand cohomology in general, and I understand the definition of cohomology but not exactly of how the diagonal determines a cohomology class.
How, rigorously, does cohomology stem from the diagonal of a surface?