  We study the production and polarization of $J/\psi$ mesons within a jet in
proton-proton collisions at the LHC. We define the $J/\psi$-jet fragmentation
function as a ratio of differential jet cross sections with and without the
reconstructed $J/\psi$ in the jet. We demonstrate that this is a very useful
observable to help explore the $J/\psi$ production mechanism, and to
differentiate between different NRQCD global fits based on inclusive $J/\psi$
cross sections. Furthermore, we propose to measure the polarization of $J/\psi$
mesons inside the jet, which can provide even more stringent constraints for
the heavy quarkonium production mechanism.
