How instantaneous is a Bitcoin transaction? How quick does a bitcoin transaction happen? (assuming that both parties are online at the time)

I read somewhere on the Internet that it's not recommended to accept a bitcoin payment right away (better to wait for a dozen or so confirmations/verification).

Why is this? and how does it affect the time it takes for the transaction to be completed?
Bitcoin transactions are saved in a ledger. There needs to be a way for everyone to agree on the same ledger. In bitcoin this is done by making sure that the only valid ledger is the one where more computing power was put into it to "generate it". There's a lot of other details, where the ledger is actually a block chain, but overall the idea is that of "the most computing power" is the rule behind how nodes accept the main ledger.

With this in mind, it still could happen that someone with a large amount of computing power may create a ledger that replaces the one that is currently accepted by the network. Because of how the block chain works, this is exponentially harder to do for every block in the ledger that is generated/found.

So to answer your question to "why is it that we need to wait for 5-6 confirmations", it's because a malicious party with lots of computing power could hypothetically replace the latest 2 blocks or so. But, to replace the latest 5 or 6 blocks it becomes so hard that it's virtually impossible for it to happen. Therefore, a transaction without any confirmations is "less secure" than a transaction with 5 confirmations. The more the confirmations, the more secure a transaction is.