Remove/Delete ":" Colon in an HTML page
html, javascript, jquery
Solution
The jQuery way, without `regex`:
$('td.quantitybox').contents().filter(function(){
return this.nodeType === 3 && // textNode
$.trim(this.nodeValue) === ":";
}).remove();
Or simply change the textnode to an empty string:
$('td.quantitybox').contents().filter(function(){
return this.nodeType === 3 && // textNode
$.trim(this.nodeValue) === ":";
})[0].nodeValue = "";
If you have multiple textnode with colons- `:` that you want to remove:
$('td.quantitybox').contents().filter(function() {
return this.nodeType === 3 && // textNode
$.trim(this.nodeValue) === ":";
}).each(function() {
this.nodeValue = "";
});
If you want to do it with `regex` and aware of it's risks:
$('td.quantitybox').html(function(i, old){
return old.replace(/:\s*</, '<');
});
Note that your HTML code in the question was edited, so I added the white space to the regex so it will work with the initial markup as well....
Problem
I dont have access to the following HTML its displayed dynamically using some External JS. ``` <td class="quantitybox"> <span class="qty">Quantity</span> <br style="clear:both;"> :<input type="text" value="1" onkeydown="javascript:QtyEnabledAddToCart();" maxlength="8" size="3" name="QTY.1121309" class="v65-productdetail-cartqty"> </td> ``` I want that : after to be Removed/Deleted using Jquery, but i am not getting what handler should be used shall i apply a class to `<br>` dynamically and do something to it