We present a novel approach for the construction of basis functions to be employed in selective or adaptive h-refined finite element applications with arbitrary-level hanging node configurations. Our analysis is not restricted to $1$-irregular meshes, as it is usually done in the literature, allowing our results to be applicable to a broader class of local refinement strategies. The proposed method does not require the solution of any linear system to obtain the constraints necessary to enforce continuity of the basis functions and it can be easily implemented. A mathematical analysis is carried out to prove that the proposed basis functions are continuous and linearly independent. Finite element spaces are then defined as the spanning sets of such functions, and the implementation of a multigrid algorithm built on these spaces is discussed. A spectral analysis of the multigrid algorithm highlights superior convergence properties of the proposed method over existing strategies based on a local smoothing procedure. Finally, linear and nonlinear numerical examples are tested to show the robustness and versatility of the multigrid algorithm.