Question

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

Was it helpful?

Solution

If you insist on a regular expression as the answer, you could use the following.

str = str.replace(/\s*<ul[^>]*>[\S\s]*?<\/ul>\s*/, '');

OTHER TIPS

Why use regex when you can use dom parsing?

var ul = document.getElementsByTagName('ul')[0];
ul.parentElement.removeChild(ul)

http://jsfiddle.net/8N2CQ/1/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top