Don't see anything wrong with your code. I made a simply assumption based on your selector. Changed the escape to single quotes as well. Not affecting the outcome. Fiddle
$("#wprmenu_menu").find('li:has(ul) > a').replaceWith(function() {
var Qthis = $(this);
var className = Qthis.attr('class');
return $("<span class='" + className + "'>" + Qthis.html() + "</span>");
});