jQuery: how to remove the text but not the children elements

Best and easy solution to remove all text elements from certain div is

$("#firstDiv").contents().filter(function(){
    return (this.nodeType == 3);
}).remove();

Leave a Comment