tags:

views:

44

answers:

3

hi,

can I remove with jQuery only the text in a node but not the children elements ?

thanks

+2  A: 
$('#someElement').text('');
Darin Dimitrov
are u sure ? it removes also the children. Maybe because I use jquery 1.2.3
Patrick
this removes all the children in 1.4.2 as well
Rudism
A: 

you cannot do that.Unless it is wrapped by an element.

+1  A: 

Here's my idea:

function removeText(element){
    var newElement = $('<' + element[0].nodeName + '/>');
    element.children().each(function(){
        newElement.append(this);
    });
    element.replaceWith(newElement);
}
Rudism