Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
61
rated 0 times [  67] [ 6]  / answers: 1 / hits: 50649  / 11 Years ago, mon, march 11, 2013, 12:00:00

I want to remove   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.


More From » html

 Answers
57

I'd suggest:



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


JS Fiddle demo.



Or, with jQuery:



$('.country-IN').html(function(i,h){
return h.replace(/&nbsp;/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.


[#79664] Sunday, March 10, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kiley

Total Points: 733
Total Questions: 118
Total Answers: 94

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
;