From the Super Mario Wiki
This article is about the generic unnamed jellyfish enemy. For information about the jellyfish-like enemy from Super Mario Bros. 3
, see Jelectro
Jellyfish are giant water-dwelling creatures that live around Yoshi's Island. They are invincible to all known means of defeat, and have a greed for intruders to their waters. Jellyfish come in Blue, Red, and Green. Blue Jellyfish simply move up and down. Red Jellyfish chase Yoshi. Green Jellyfish simply float in place. Red Jellyfish can sometimes have an item like a Fruit or a Heart Fruit.
It is entirely possible that Jellyfish are related to Jelectros, another type of jellyfish enemy found in Super Mario Bros. 3. Pre-Yoshi's Story jellyfish also appeared in Super Mario World 2: Yoshi's Island, going under the name "Preying Mantas".
Mario & Wario
In Mario & Wario, Wario uses a jellyfish on one stage to obscure Mario's view.
In Yoshi's Story, Jellyfish only appear in the level Lots O'Jellyfish!. Green ones don't appear until the third part of the level.
Blue jellyfish go up and down, red jellyfish will chase Yoshi and green jellyfish just hover.
Super Mario Galaxy
in Super Mario Galaxy
In Super Mario Galaxy, Jellyfish appear in a few galaxies, in the Deep Dark Galaxy and the Bigmouth Galaxy. In this game, they are blue, and are very large. If Mario comes in contact with one, he will be shocked. They could only be defeated by hitting them two times with a Koopa Shell, and would give one Coin when defeated.
Super Mario Galaxy 2
In Super Mario Galaxy 2, a Jellyfish appears in the Cosmic Cove Galaxy. It behaves the same way as in the predecessor, but instead of giving a Coin when defeated, it will give ten Star Bits.