views:

31

answers:

1

I have <li> elements in my document such as:

<li id="123" onMouseOver="foo();">Lorem Ipsum ...

I would like to remove the attributes and get the string <li>Lorem Ipsum .... In order to do that, I use the replace() method:

foo = document.getElementById('bar');
alert(foo.innerHTML.replace('<li(.*)', '<li>'));

But it won't match and returns the exact same string. <li\(.*\) was no good either. I tried the regex here and it worked. Any suggestions? Would DOM solve this instead of Regex?


EDIT: Turns out I used the replace method wrong, instead of a pattern I should have provided a Regexp object. Thanks to Gobi's answer I corrected my pattern too.

A: 

Try <li[^>]*> or <li.*?> instead.

However, using html parser instead of regex is always advised.

Gopi