In this article, a class of variable-order differential equations is solved by the Ritz-approximation. Firstly, the unknown function is estimated using the Ritz-approximation and Genocchi polynomials as the basis functions. Then, by collocation method and preference of Genocchi roots as the node points, a set of algebraic equations is obtained. This system of nonlinear equations is solved by Mathematica 10 software. Finally, by solving some numerical examples and comparing the achieved results with other methods, the validity and efficiency of the presented method are shown.