Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6656421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:38:27+00:00 2026-05-26T01:38:27+00:00

If there were two <ul> ‘s, one called list_a and the other called list_b

  • 0

If there were two <ul>‘s, one called list_a and the other called list_b, using javascript and not using any libraries like jQuery, how would you delete the <li>‘s in list_a that have the same value as those in list_b?

Heres the example HTML:

  <ul id="list_a">
    <li value="1">list_a_0</li>
    <li value="8">list_a_8</li>
    <li value="9">list_a_9</li>
  </ul>

  <ul id="list_b">
    <li value="8">list_b_8</li>
    <li value="9">list_b_9</li>
    <li value="2">list_b_2</li>
  </ul>

The end result should be:

  <ul id="list_a">
    <li value="1">list_a_0</li>
    <!-- DELETED TWO <li>'s -->
  </ul>

  <ul id="list_b">
    <li value="8">list_b_8</li>
    <li value="9">list_b_9</li>
    <li value="2">list_b_2</li>
  </ul>

The javascript so far that I can build (that doesn’t work) is:

window.onload=function()
{
  init();

  function init()
  {
    var listA = document.getElementById("list_a");

    for(var i in listA.childNodes)
    {
      var x = listA.childNodes[i];
      var listB = document.getElementById("list_b");

      for(var j in listB.childNodes)
      {
        var y = listB.childNodes[j];
        if(x.innerHTML == y.innerHTML)
          listA.removeChild(listA);
      }
    }          
  }  
}

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:38:28+00:00Added an answer on May 26, 2026 at 1:38 am

    DEMO: http://jsfiddle.net/rmXrZ/

    window.onload = function() {
    
        var listA = document.getElementById("list_a");
        var listB = document.getElementById("list_b");
    
        for (var i = 0; i < listA.children.length; i++) {
            var x = listA.children[i];
    
            for (var j = 0; j < listB.children.length; j++) {
                var y = listB.children[j];
                if (x.value == y.value) {
                    listA.removeChild(x);
                    i--;
                }
            }
        }
    }
    
    • Don’t use for-in for iteration of numeric indices

    • Cache the DOM selection instead of re-selecting in the loop

    • Use .children instead of .childNodes to avoid text nodes between elements

    • Compare .value instead of .innerHTML

    • Remove x instead of listA

    • When an element is removed from listA, decrement i, because removal from the DOM means removal from the .children collection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are two types of query parameters binding in the Hibernate Query. One is
There are two tables. One is users info users, one is comments info comments.
How is 'Any CPU' implemented on low level? Aren't there two formats: PE32 and
Hi i have notice there two date times facebook gives, one is a date
There are two attributes like this: [AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)] sealed
To begin, not only are there two main dialects of the language (Common Lisp
I have read a document that they say: In java there two types of
There are two things that seem to be popular nowadays and I was wondering
There are two options when setting up your JBPM session. You can put your
There are two classes: A and B . There are algorithms for converting from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.