Remove from html
5 answers
I would suggest:
var el = document.querySelector('.country-IN');
el.innerHTML = el.innerHTML.replace(/ /g,'');
Or with jQuery:
$('.country-IN').html(function(i,h){
return h.replace(/ /g,'');
});
Or even:
$('.country-IN').children().each(function(i,e){
this.parentNode.removeChild(this.nextSibling);
});
Though it would be easier to just edit the HTML files themselves and just remove those character lines.
+13
source to share
Library Agnostic:
(function() {
var country_els = document.querySelectorAll('.country-IN');
for (var i = 0; i < country_els.length; i++) {
for (var j = 0; j < country_els[i].childNodes.length; j++) {
var node = country_els[i].childNodes[j];
if (typeof node.tagName === 'undefined') {
node.parentNode.removeChild(node);
}
}
}
})();
0
source to share
First, get the entire HTML div file and convert it to string
convertHtmlToText(str)
{
str = str.toString();
return str.replace(/<[^>]*(>|$)| |‌|»|«|>/g, ' ');
}
you will get text without HTML tag and & nbsp etc.
You can add multiple conditions in the above solution
0
source to share