Officially: Unfortunately, it is not allowed for any passenger regardless of age to be admitted to the flight deck. This is according to the FAA (USA) and to the EASA (EU), as seen in:
Most of the world follow the above organizations, either directly or by implementing similar operating procedures and policies, I am not aware of any civil aviation authority that allows passengers to visit the flight deck.
Anyway, reality is a bit different as usual. Out of personal experience as a cabin crew member, here are few tips that could help you in getting your children or even yourself to the cockpit:
Ask a cabin crew member with a smile, while presenting your business card, to ask the captain for you if he will allow your child to go inside the cockpit. The cabin crew member will go to the cockpit and deliver the message to the captain. The captain might let your child in, asking to let child in has better chances than asking for yourself as an adult. If the captain refused, usually he will tell you through the cabin crew that you are welcomed on ground prior to leaving the aircraft.
Captains in long flights usually take a walk around in the cabin to stretch their legs or when the other set of cockpit crew (in case of double crew) are flying. Once you see him/her introduce yourself and your children to him, ask him nicely that the kids want to see the cockpit. Most likely in this case he will agree. You just need some luck.
PS: I once around 2005 or 2006 was a passenger on a flight (different airline, not the one I work for) and I saw the captain in the aisle and we had a little chat. I ended up in the cockpit having a cigarette with him :)