Impossible to say for certain, but most likely it's either the battery or the mains adapter.
Laptops will normally work just fine off mains power alone, but a dead battery (I mean truly dead, not just worn out) could stop it working. Take the battery out and try running it just on the mains adapter. If it now works, you need a new battery, or content yourself with running it just on mains.
If it dies after a few seconds like you described just on mains power, it could well be the mains adapter. Perhaps you can find a friend or colleague who has an HP with the same kind of adapter. So long as the plug on the laptop end of the adapter is the same size, and the output voltage written on the adapter is the same, it should be compatible. If this works, you need a new adapter.
Replcement batteries and adapters are fairly readily available on places like eBay, but don't go for the cheapest or one from a seller with less than an excellent reputation as there are some poor quality ones out there, especially for popular brands of laptop.
If it's neither the battery nor the adapter, it could be a motherboard fat, which would be more challenging. Good luck!
Regards - Philip