remove <Ll> from <UL> with Javascript

Hello everyone,
A quick question in case someone might know the answer,
 In my html page I have a list like

<ul id="thang">
<LI><a href="http://bobby.com">bobby</a>
<LI><a href="http://sally.com">sally</a>
<LI><a href="http://franklin.com">franklin</a>
<LI><a href="http://frankie.com">frankie</a>
<LI><a href="http://jimmy.com">jimmy</a>
</ul>


does someone know if there is a javascript solution  
that will, after the page loads, remove franklin from this list, including the link
the links do not have an ID. I have found a way to remove the text "franklin" but want to
remove the entire list item


thank you very much for your time.
forcedexposureAsked:
Who is Participating?
 
HonorGodSoftware EngineerCommented:
Sure... something like this should do it for you
function noFrankie( obj ) {
  var lis = obj.getElementsByTagName( 'LI' )
  for ( var i = lis.length - 1; i > -1; i-- ) {
    if ( lis[ i ].firstChild.firstChild.nodeValue == 'franklin' ) {
      obj.removeChild( lis[ i ] )
    }
  }
}

Open in new window

0
 
forcedexposureAuthor Commented:
SORRY, each <LI> in the list is close with </LI>
MY MISTAKE!
0
 
HonorGodSoftware EngineerCommented:
something like this perhaps?

and calling it using something like:

cleanup( document.getElementById( 'thang' ) )
function cleanup( obj ) {
  var lis = obj.getElementsByTagName( 'LI' )
  for ( var i = lis.length - 1; i > -1; i-- ) {
    obj.removeChild( lis[ i ] )
  }
}

Open in new window

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
forcedexposureAuthor Commented:
thank you for your time,
your code is very close to what i am looking for and is
very helpful

For me, Your code is removing the entire list
 when called with cleanup( document.getElementById( 'thang' ) )

is there a way to only remove items on the list with the name 'franklin' ?

thank you
0
 
forcedexposureAuthor Commented:
HonorGod,

Thank you kindly.
Your solution was EXACTLY what I was looking for.

Have a good one!!!
0
 
HonorGodSoftware EngineerCommented:
You are very welcome.

Thanks for the grade & points.

Good luck & have a great day.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.