You have to escape '|' character:
txt=txt.replace (/\|/g, '');
Question
My question may find simple, But I am not getting it right. How could I remove "|" from a string so far I have used the following but Its not working
<div class="inner"> | ABCD || </div>
var txt=divVar.html();
1) txt=txt.remove("|");
2)txt=txt.replace (/|/g, '');
Solution
You have to escape '|' character:
txt=txt.replace (/\|/g, '');
OTHER TIPS
If you want to remove just '|' and not '||' than you can use the below mentioned solution
<div class="inner"> | ABCD || </div>
<script type="text/javascript">
$(document).ready(function () {
var str = $(".inner").html();
alert(str);
var FormatedStr = str.trim().replace('|', '');
alert(FormatedStr);
});
</script>
Else, if you want to replace both than use below
<div class="inner"> | ABCD || </div>
<script type="text/javascript">
$(document).ready(function () {
var str = $(".inner").html();
alert(str);
var FormatedStr = str.trim().replace('|', '').replace('||', '');
alert(FormatedStr);
});
</script>
Hope this help you to solve your problem
Thanks Prashant