Remove   from html

css, html, javascript, jquery

Solution

I'd suggest:

var el = document.querySelector('.country-IN');
el.innerHTML = el.innerHTML.replace(/ /g,'');

JS Fiddle demo.

Or, with jQuery:

$('.country-IN').html(function(i,h){
    return h.replace(/ /g,'');
});

JS Fiddle demo.

Or even:

$('.country-IN').children().each(function(i,e){
    this.parentNode.removeChild(this.nextSibling);
});

JS Fiddle demo.

Though it'd be easier to simply edit the HTML files themselves and just remove those strings of characters.

Problem

I want to remove `&nbsp;` from the below code. ``` <div class="country-IN"> <span class="locality">Barnala</span> &nbsp;&nbsp; <span class="state">Punjab</span> &nbsp;&nbsp; <span class="country">India</span> </div> ``` Please help me to get out of it.

Original source