Fire burns Flesh; most "meaty" foes take extra damage from thus unless they resist fire (like burning psychos) or if you shoot their armor. Flesh enemies have a red health bar. Flesh enemies are extremely common, especially in the beginning of the game, so Fire is almost always helpful. Fire does much less damage to shields and armor (half or less) and many Armored foes resist Fire, so keep your fire guns away when Armored foes are about and until your target's shields are down.
Fire sets enemies on fire and causes them to panic (I'm not sure if they actually act differently yet, they did in BL1). When on fire enemies take a moderate amount of damage over a few seconds. If you note how much damage your burn effects are doing you can stop firing on an enemy once you're sure your burn Damage Over Time will kill them, making you more efficient. Remember Damage Over Time stacks so get a few good Fire effects stacked on a target before you leave them for dead.
Shock fries shields; any enemy with a blue Shield bar over their health bar will take 2x as much damage from Shock (2.5x in playthrough 2). Shock does normal damage to Flesh and Armor, so there's no need to switch guns when a target's Shield is down.
Also note that cloaked/invisible enemies can only cloak when their shields are up; additionally they all seem weak or at least vulnerable to Shock damage. Shock weapons make quick work of Hyperion Infiltrators and Stalkers.
Shock has a brief Damage Over Time effect; unlike Fire and Corrosive it does it's DOT very quickly, so concentrate fire on foes and let the DOT stack until they die. Alternately wipe out every targets' shields so your buddies can deal health damage.
Corrosive eats armor. Any enemy with a yellow "metal" health bar has Armor and other targets can have armored parts. Corrosive shots do less damage to health and even less damage to shields. Save corrosive guns for armored targets, but they do well enough against health in a pinch.
Targets under Corrosion are covered in green acid and the effect of their armor is weakened, which is useful in Coop when your buddies don't have corrosive guns. Corrosion lasts a long time and deals damage fairly slowly. You can stack a few Corrosion effects on multiple targets and let it eat away their health, especially effective in Coop so multiple people can take advantage of the multiple corroded targets.
Slag doesn't do extra damage on it's own, but has a chance to Slag an enemy. Purple Slagged targets take double damage from all non-slag damage for several seconds. Enemies don't appear to resist Slag as an element, but some are immune to the status effect itself. Some bosses can be slagged.
Slag is best used in coop as you can slag enemies which will take double damage from your buddies without slag damage; the more people using non-slag weapons, the more damage you can deal to a slagged target. Alternately you could use Slag grenades and non-slag guns or quickly switch to a different gun to hit a slagged target, but your weapon-switch time may eat up much of the Slag effect's length. Slag doesn't appear to "stack" in any meaningful way.
Sirens can also inflict Slag with Phase Lock via the last skill in the Cataclysm tree, or via their Melee Override Scorn in the Harmony tree. Axton can inflict slag via turrets with the Double Up skill from the Guerrilla tree.
Explosive is the odd one out as it doesn't have a % chance of happening; explosive guns' bullets always explode and always deal a little extra damage. Explosives only deal 80% damage to shields but otherwise do normal damage to all enemies.
Explosive shots don't have a Damage Over Time effect, instead explosive bullets have a splash damage radius and always deal a little more damage per bullet than their weapon stats indicate; an explosive gun with 100 damage will hurt more than a non-elemental weapon on a direct hit, and splash damage means enemies near the bullet's impact still take damage. Multiple close together enemies can be hurt at once, too. Unlike other elements there's usually no reason to swap out Explosive guns because of an enemy's resistance, though Shields take slightly longer to take down.
As a downside to the consistently stronger damage per shot is that explosive damage can't Critical, a direct head shot from an explosive gun still isn't critical. Rocket Launchers are similarly non-critical; it's really due to splash damage more than the element, but Explosive always has splash damage. Interestingly enough, any target within the splash damage range recieves full damage; it's all or nothing, and it doesn't usually matter where the shot landed on the target.
As I note in How long do elemental damage effects last?, each elemental DoT effect lasts different lengths.
- Fire: 5 seconds
- Shock: 2 seconds
- Corrosive: 8 seconds
- Slag: 8 seconds
So, if you're patient, a Corrosive DoT for 50 damage/sec will do much more damage than a Shock DoT for 100 damage per second.
Second Playthrough Changes
As a special note, elemental differences become more pronounced on the second playthrough; damage bonuses are slightly stronger (except for Slag), and weaknesses are more pronounced. For example Corrosive will deal even more damage to Armor but be even weaker against Flesh. In your second playthrough you'll have to be even more picky about which element you use.
The Borderlands 2 wiki has great damage tables for elemental effects, reproduced here with attribution: