javascript - Remove character from code with jQuery -


i'm trying remove em dash pre made piece of code. however, imbedded in tree , cannot seem access it:

jsfiddle

html:

  <span class="price">                    <span class="price">             <span class="amount">£8.75</span>             – // need this!             <span class="amount">£19.20</span>         </span>     </span> 

js:

$('span.price').each(function(){     $(this)         .find('.amount')         .next()         .remove()      var c = $(this);     var t  = c.text();     var b = t.replace('—', '@'); // if use ('£', '@') replaces pound sign     c.text(b);  }); 

would know why above not find , replace '—' dash?

you can use combination of .contents() , .filter find text nodes content - , remove it:

$(".price").contents().filter(function() {     return this.nodetype == 3 && $.trim(this.textcontent) === "–"; }).remove(); 

jsfiddle

edit: changed use jquery's trim rather es5 work on < ie9


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -