I selected the glass which is glass, but under the shading, all the nodes are the donuts. What did I do wrong that the nodes are not matching with the selection?
You selected an object. That does not necessarily select the material you intended to select on it. You need to do that in the Material tab in the Properties Editor:
In order to assign materials to different parts of an object you need to select desired faces in edit mode and click assign in the Material tab in the Properties Editor:
It is also quite important to name your materials appropriately. It might not be a problem for you now to have Material.001, Material.002 and Material.003, but once you work on anything more than a few objects with 3 or 4 materials, it will get very confusing if you don't name things. It's better to make a habit out of it.