javascript - Replace specific text without affecting styling -
need replace colons wherever they're found in specific elements id's. works reason replaces styling attached elements:
$(document).ready(function(){
$("#element").each(function () { //for element var s=$(this).text(); //get text $(this).text(s.replace(/:/g, ' ')); //set text replaced version });
});
i tried attaching class element made no difference. how remove colons without affecting else? demo
what html code in #element ?
if replacing text in #element
changes style, means #element
contains html tags (and style applied on tags).
try this:
$(document).ready(function() { $("#element").each(function () { (function trim_colons(el) { (var = 0; < el.childnodes.length; ++i) { var c = el.childnodes[i]; if (c.nodetype == 1) trim_colons(c); else if (c.nodetype == 3) c.nodevalue = c.nodevalue.replace(/:/g, ' '); } })(this); }); });
this correctly remove :
characters, without changing style.
Comments
Post a Comment