>>13237232it's a good question, it's just not easy to answer in a few sentences.
from the lorentz force law it is immediately obvious the B field does no work because the magnetic force is perpendicular to velocity. end of story.
so you are wondering how can two magnets attract each other? it seems like a force is pushing the magnets together and along a displacement to boot, thus work must be done! but if the magnetic force is not responsible, than what is doing the work.
what i'm saying is a detailed analysis reveals that it is the electric field doing work on moving charges (i.e. current). how can this be?
well, consider the most simple electromagnet possible, a little loop of wire with a current going around it. it produces an inhomogeneous magnetic field. next consider a second magnet that is also just a loop of wire with a current going around it, and put it some distance away from the first loop but on the same axis. when you apply the force law to the loop, you see that there is a net force because B is inhomogeneous. since this force points along the axis, you get an acceleration. now allow the loops to move closer together. follow a charge that is part of the current around the loop. since the magnetic flux in the loop is changing, an emf is inducing an E field that opposes the motion of the charge. thus the magnets are doing work on each other.