Maximum checked checkboxes in specifck div's

Maximum checked checkboxes in specifck div's

I'm trying to get this for about two days now but just can't figure it out.

I would like some kind of function that let's me use a ID as selector, when a checkbox's is clicked (checked) in that div it counts that checked checkbox. When there are 4 checkboxes checked there must be a action (the other checkboxes get disabled).
I just can't set it up. Maybe someone could help me out with a snippet? Thanks in advance.