问题
how i can remove with js the ul tags and all the content? example
<div>
<ul>
<li>a</li>
<li>b</li>
</ul>
</div>
i want this
<div></div>
i use
var.replace('regex', '');
anyone can help me?
Ps. only js, i can't use Jquery
回答1:
If you insist on a regular expression as the answer, you could use the following.
str = str.replace(/\s*<ul[^>]*>[\S\s]*?<\/ul>\s*/, '');
回答2:
Why use regex when you can use dom parsing?
var ul = document.getElementsByTagName('ul')[0];
ul.parentElement.removeChild(ul)
http://jsfiddle.net/8N2CQ/1/
来源:https://stackoverflow.com/questions/23542995/how-remove-ul-tags-and-all-enclosed-contents-in-js-with-regex