I want to replace every <li>
tag with #
& every </li>
with <br />
I think I need a global replace function for that rather than a simple string.replace()
so...
var s=obj1.innerHTML;
s = s.replace(/<li>/g,"# ");
s = s.replace(/</li>/g,"<br/>");
But it doesn't seem to be working. Any mistake ?
EDIT: I am going to use the code in blogger & that is why it needs to be parsed.So that's why you see "
instead of "
.
Do this way:-
LIVE DEMO
var s="<div>hello world <br/><li>First LI</li><li>Second LI</li></div>";
s = s.replace(/<li>/g, "#");
s = s.replace(/<\/li>/g,"<br/>");
alert(s);
obj1.innerHTML = obj1.innerHTML.replace(/<li>/g, '#').replace(/<\/li>/g, '<br>');
You just have to escape the /
in /li
otherwise it will be taken as a regex delimiter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With