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 7918573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:33:18+00:00 2026-06-03T15:33:18+00:00

html code <li id="ioAddOtherRelation"> <a href="" onclick="return ioAddSetOtherRelation()"class="smallLink">add other relation</a> </li> and i want

  • 0

html code

<li id="ioAddOtherRelation">
            <a href="" onclick="return ioAddSetOtherRelation()"class="smallLink">add other relation</a>
</li>

and i want the function ioAddSetOtherRelation to remove the a tag

javascript code

function ioAddSetOtherRelation(){
    var bigLi = document.getElementById('ioAddOtherRelation');
    bigLi.removeChild(bigLi.childNodes[0]);
    return false;
}

when i press the link for the first time ,nothing happend , but when i press it twice it remove the a tag , i want to remove the a tag in one click

  • 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-06-03T15:33:21+00:00Added an answer on June 3, 2026 at 3:33 pm

    The problem with the code you posted is that the first child of your ‘li’ element is actually a textNode containing the newline and whitespace between itself and the ‘a’ element. The first time you click, this invisible textNode is removed and the second time you click the ‘a’ is removed.

    You can demonstrate this by removing the newline and whitespace (i.e. put all the HTML on one line with no spaces) – you should see the ‘a’ disappearing on the first click.

    I found that the following modified javascript worked as you intended. Note I’ve used .getElementsByTagName() to make sure that only ‘a’ elements are returned. this will return an array like .childNodes would, so I’m taking the first element of the resulting array.

              function ioAddSetOtherRelation() {
              var bigLi = document.getElementById('ioAddOtherRelation');
              bigLi.removeChild(bigLi.getElementsByTagName("a")[0]);
              return false;
          }
    

    I found FireBug to be very useful in solving this problem (together with console.debug() lines in the JS code) – if you’re not already using that I’d recommend giving it a go!

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

Sidebar

Related Questions

This is a simple code : HTML <a id="link" href="#">Ciao</a> jQuery $('#link').click(function () {
I have this code : HTML <a href="javascript:void(0);" id="showDiv">Show Agency</a> <div id="invisibleDiv"> <script src="http://platform.linkedin.com/in.js"
I have this code : HTML <div class="draggable_main_container"> <div class="draggable_container"> <div class="draggable"> <div class="minus">
Original I want to parse a string of html code and add newlines after
This is my code : HTML <div style="display:none;"> <div id="example"> <div class="child">Hello</div> </div> </div>
This is my code : HTML <div id="fb-root"></div><script>window.fbAsyncInit = function() { FB.init({ appId: '1234',
My cUrl call is returning HTML code like: &quot;Some stuff.&quot; and I'd like to
Below are the options that I have in my HTML code: <label id="subn"> <select
Check this code : HTML : <div style="position: absolute; visibility: visible; width: 172px;"> <img
This is my code : HTML: <div id="container"> <div id="box"> Content </div> </div>​ CSS:

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.