In this talk we will discuss the recent development of locally divergence-free discontinuous Galerkin methods for solving Maxwell equations and ideal magnetohydrodynamics (MHD) equations. The distinctive feature of such methods is the use of approximate solutions that are exactly divergence-free inside each element for the part of the solution which should be divergence-free, such as the velocity in the Maxwell equations and the magnetic field in the MHD equations. As a consequence, this method has a smaller computational cost, equal or better accuracy and the same or better stability properties, than the traditional discontinuous Galerkin method with standard piecewise polynomial spaces. Results by our extensive numerical experiments for the Maxwell equations and for the MHD equations, and by theoretical analysis in the case of the linear Maxwell equations will be shown. The spirit of this approach can also be used to solve other problems, such as a (reinterpretation of) discontinuous Galerkin method for solving Hamilton-Jacobi equations. This is joint work with Fengyan Li and (part of it) with Bernardo Cockburn.