I had a similar question posted previously but this is a little bit different. I am looking to remove the colon from the below price code utilizing jQuery.
<font class="pricecolor colors_productprice">
<div class="dealtext"></div>
: $58.05
</font>
So far I believe it could be somewhat accomplished like this, I just need another set of eyes to correct it:
$('.pricecolor:开发者_JS百科contains(" : ")').remove(colon??);
It still doesn't seem right, perhaps I need a var set with a get()
?
$('*').each(function() {
$(this).html($(this).html().replace(":", ""));
});
I found this question as I needed it and I ultimately used this function to do something similar...
$('.pricecolor:contains(" : ")').html(function(index,oldhtml) {
return oldhtml.replace(' : ','');
});
function findAndReplace(elements, textToFind, textToPlace) {
$.each(elements.contents(), function () {
// This is added to make sure the nodes you request are text nodes
if (this.nodeType == 3)
this.nodeValue = this.nodeValue.replace(textToFind, textToPlace);
});
}
findAndReplace($('div.dealtext'), ':');
I think you can do something like below.
$(".pricecolor colors_productprice").html($(".pricecolor colors_productprice").html()replace(/:/g, ""))
Hope this helps!!
var e = $(".pricecolor:contains(':')");
e.text(e.text().replace(/\s*:\s*/, ''));
This will work:
$(".pricecolor:contains(' : ')").each(function(){
$(this).html($(this).html().replace(" : ", ""));
});
Give this a shot:
$('.pricecolor:contains(" : ")').text(function(index, text) {
return text.replace(/:/g, "");
});
I think you need to pass a function instead of a string to $.text() like this to avoid mangling other content that was found using the '.pricecolor:contains(" : ")' selector.
精彩评论