Reputation: 57
<div id="googlefy">
<div class="skiptranslate">
<div>....</div>
<div id="">
hello by
<span style="white-space:nowrap">....<span>
</div>
</div>
now i want to remove text hello by. how do i do?
when i using $("#googlefy:contains('hello by')").remove()
. it remove all the html.
Upvotes: 0
Views: 120
Reputation: 196
$(".skiptranslate").find('div:last-child').text().replace('hello by','');
Upvotes: 0
Reputation: 1095
To be practical I recommend enhancing the document structure. You may add a class just for elements to be cleared.
<div id="googlefy">
<div class="skiptranslate">
<div>....</div>
<div>
<span class="clear_this">hello by</span>
<span style="white-space:nowrap">....<span>
</div>
</div>
Then you may remove the node (including the <span>
tag) using $('.clear_this').remove()
or keep the <span>
by setting $('.clear_this').text("")
Also note that id
in html shouldn't be blank when specified.
Upvotes: 0
Reputation: 382160
Supposing you don't want to remove a specific text but need a generic solution, this code removes all texts at the start of the div :
var div = document.getElementById('yourid');
while(div.childNodes[0].nodeType==3)
div.removeChild(div.childNodes[0]);
Upvotes: 0
Reputation: 16544
Try this, it will only remove "hello by"
$('#googlefy').html($('#googlefy').html().replace(/hello\sby/, ""));
Upvotes: 2