문제

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

도움이 되었습니까?

해결책

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

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

다른 팁

Why use regex when you can use dom parsing?

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top