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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:59:54+00:00 2026-06-03T14:59:54+00:00

hi I want to add elements to LI when pressing on a link I

  • 0

hi I want to add elements to LI when pressing on a link
I can add elements to a DIV like this

I have seen this question too Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

html code

<div id="div">
<a href="" onclick="add()">add</a>
</div>

javascript code

function add(){

    var bigDiv = document.getElementById('div');
    var input = document.createElement('input');
    input.setAttribute('type', 'text');
    bigDiv.appendChild(input);
    }

and it works good
but if I change the html code from div to li like this

html code

<ul>
<li id="li">
<a href="" onclick="add()">add</a>
</li>
</ul>

javascript

function add(){
var bigLi = document.getElementById('li');
var input = document.createElement('input');
input.setAttribute('type', 'text');
bigLi.appendChild(input);
}

it doesn’t work
I ensure that there is no syntax error

  • 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-03T14:59:56+00:00Added an answer on June 3, 2026 at 2:59 pm

    check your HTML:

    • you have no closing </a>
    • your onclick code isn’t wrapped in "" like onclick="add()"
    • you didn’t suppress the link’s default action (which is to redirect). try adding href="#" to prevent it from moving away and add return false to the end of the function.

      <a href="#" onclick="add()">a</a>
      
      //AND
      
      function add(){
          ...
          return false;
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add elements to my Hash lists, which can have more than
I want to add elements to arrays within an object that I access like
So, I have these h1 elements that are links and I want to add
like array(a, b, c, d, e); I want to add new elements to it,
I want to know how can I add elements to page without breaking line
I have an SVG that I will add elements to. And on mousemove this
I want to add some HTML elements that have the same class name. So,
Suppose I have an iterator, and I want to add some elements before or
I want to add elements to a collection that ends up getting mapped like
I have an arraylist where I want to add elements via a for loop.

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.