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:
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(); edit: changed use jquery's trim rather es5 work on < ie9
Comments
Post a Comment