?
Solved

remove <Ll> from <UL> with Javascript

Posted on 2009-04-28
6
Medium Priority
?
242 Views
Last Modified: 2012-05-06
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.
0
Comment
Question by:forcedexposure
  • 3
  • 3
6 Comments
 

Author Comment

by:forcedexposure
ID: 24251226
SORRY, each <LI> in the list is close with </LI>
MY MISTAKE!
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24251381
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
 

Author Comment

by:forcedexposure
ID: 24251555
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 41

Accepted Solution

by:
HonorGod earned 2000 total points
ID: 24251718
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
 

Author Comment

by:forcedexposure
ID: 24252107
HonorGod,

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

Have a good one!!!
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24252698
You are very welcome.

Thanks for the grade & points.

Good luck & have a great day.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
If anyone asked you to network diagram of the internet, it was drawn in the form of a fluffy cloud which further became known as cloud computing. Popularly cloud computing is defined as workloads that run over the internet in a commercial provider’s…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question