Link to home
Start Free TrialLog in
Avatar of forcedexposure
forcedexposure

asked on

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.
Avatar of forcedexposure
forcedexposure

ASKER

SORRY, each <LI> in the list is close with </LI>
MY MISTAKE!
Avatar of HonorGod
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

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
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
HonorGod,

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

Have a good one!!!
You are very welcome.

Thanks for the grade & points.

Good luck & have a great day.