Abstract : Jet fragmentation in pp and PbPb collisions at a centre-of-mass energy of 2.76 TeV per nucleon pair was studied using data collected with the CMS detector at the LHC. Fragmentation functions are constructed using charged-particle tracks with transverse momenta pt > 4 GeV for dijet events with a leading jet of pt > 100 GeV. The fragmentation functions in PbPb events are compared to those in pp data as a function of collision centrality, as well as dijet-pt imbalance. Special emphasis is placed on the most central PbPb events including dijets with unbalanced momentum, indicative of energy loss of the hard scattered parent partons. The fragmentation patterns for both the leading and subleading jets in PbPb collisions agree with those seen in pp data at 2.76 TeV. The results provide evidence that, despite the large parton energy loss observed in PbPb collisions, the high-pt component of the fragmentation function evaluated with respect to the reconstructed jet momentum is not strongly modified in comparison to jet fragmentation in vacuum.