Coastal habitats are heavily subjected to eutrophication and commercial fisheries, and such alterations can affect organism interaction strengths and potentially influence trophic dynamics. A key species inhabiting coastal environments in temperate waters is the Atlantic cod Gadus morhua, which utilises coastal areas for food and shelter. We used an experimental mechanistic approach to assay prey selectivity by juvenile cod when foraging on grass shrimp Palaemon elegans and brown shrimp Crangon crangon, under light and dark conditions, in 3 of the most abundant habitat types in temperate coastal environments-sand, eelgrass (artificial vegetation mimicking Zostera marina), and bladderwrack Fucus vesiculosus. Using functional response relationships from single-prey experiments, we calculated the energetically best foraging strategy for cod in the 3 habitats, i.e. feeding selectively on either of the shrimp species or on a combination of both. These predictions were tested in experiments where the cod predator was offered both prey species. Cod selected both prey species in accordance with our predictions in eelgrass and in bladderwrack under light conditions, but a lower than predicted consumption of grass shrimp was found in sand and in bladderwrack under dark conditions. Cod decreasingly selected grass shrimp with increasing habitat complexity, i.e. the highest selectivity was in sand and the lowest selectivity was in bladderwrack. As the 2 shrimp species have different trophic roles, cod selective predation may have effects on lower trophic levels. We provide a quantitative prediction of cod selective predation in habitat types that undergo degradation, and suggest that such predation can influence the trophic consequences from environmental change.