You are dealing with a nested selection. First, you don't need to re-bind the data to the nested element, it's automatically passed. Second, you aren't handling the enter, update and exit selections properly. Re-factored it would look like this:

// update selection
var p ="body")

// those being removed

// those entering
var pEnter = p.enter()
  .attr("class", "lol");

// append a span to those entering

// this is update + enter
p = pEnter.merge(p);

// update the update + enter selection's sub-selection"span").html(function(d) { return d });        

Updated fiddle.

Related Query