Remove <li>'s with a custom attribute value

I have a number of <li> elements that look similar to this:

<li id="post-142511" class="message  " data-author="author1">

I need to be able to remove the one’s where data-author=“author1”, (there is more than one).

Any ideas on the most efficient way to do this?

Presumably you’re not worried that “data-author” won’t validate as a known attribute. This isn’t tested but you can try it, otherwise it may be necessary to use getAttribute.

var allItems = document.getElementsByTagName( 'LI' );

for( var i = 0, anItem; ( anItem = allItems[ i ] ); i++ )
 if( anItem[ 'data-author' ] )
  anItem.parentNode.removeChild( anItem );

Thanks. With the getAttribute I need to be able to specify what the value of data-author is. So if data-author = “author2” I do not want to remove it. If it’s “author1”, I do.

OK I missed that part so try this, which will be case-sensitive:

var allItems = document.getElementsByTagName( 'LI' );

for( var i = 0, anItem; ( anItem = allItems[ i ] ); i++ )
 if( anItem[ 'data-author' ] == 'author1' )
  anItem.parentNode.removeChild( anItem );