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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:18:06+00:00 2026-06-05T04:18:06+00:00

We have had quite long chat here with rlemon about DOM manipulation. Basically the

  • 0

We have had quite long chat here with rlemon about DOM manipulation. Basically the question is 'How can I change the UL-LI DOM with Javascript?' For example, suppose I want, instead of "<ul id='uids'><li>1</li><li>2</li></ul>", to display something like this "<ul><li><i>Hello 1, have a nice day!</i></li>...</ul>" — how can I do that just with DOM -manipulation?

I know this is simple question so instead of reinventing-the-wheel, I am happy with references.

Simple demo about DOM manipulation, can you do something like this?

Input

    <ul id="uid">
            <li>1</li>
            <li>2</li>
    </ul>

Output

    <ul id="uid">
            <li>Hello beautful lady 1!</li>
            <li>Hej gentleman 2.</li>
    </ul>

Perhaps useful for other newbies to get familiar with functional nature of JS

  1. https://chat.stackoverflow.com/rooms/17/conversation/learn-javascript-videos

  2. http://ejohn.org/apps/learn/

  • 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-05T04:18:08+00:00Added an answer on June 5, 2026 at 4:18 am

    The short way, using innerHTML:

    var lis = document.getElementById("uid").getElementsByTagName("li");
    for(var i = 0; i < lis.length; i++)
        lis[i].innerHTML = "<i>Hello "+lis[i].innerHTML+", have a nice day!</i>";
    

    jsFidlde: http://jsfiddle.net/eZv4D/3/

    The long way, with true DOM manipulation:

    var lis = document.getElementById("uid").getElementsByTagName("li");
    for(var i = 0; i < lis.length; i++) { // Loop through all <li> elements
        // Create an <i> element to contain the text
        var el = document.createElement("i");
    
        // Add the start of the text to the <i>
        el.appendChild(document.createTextNode("Hello "));
        // Add everything in the <li> to the <i> (they are removed from the <li>)
        while(lis[i].firstChild)
            el.appendChild(lis[i].firstChild);
        // Add the end of the text to the <li>
        el.appendChild(document.createTextNode(", have a nice day!"));
    
        // Add the <i> to the <li>
        lis[i].appendChild(el);
    }
    

    ​
    ​
    jsFiddle: http://jsfiddle.net/eZv4D/2/

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

Sidebar

Related Questions

This is quite a specific question, and I have had no luck on the
I've had quite a long discussion with a friend of mine about the correct
I have had some long standing code which has worked fine for quite some
I've done quite a bit of googling on this error but have had no
I have had a talk with a friend of mine about the relative vulnerability
I have been using Java for a long time, and for quite some time
This is quite a long introduction to a simple question, but otherwise there will
The text is quite long, the question is actually simple and written in bold
I have quite a long data mining script, and in parts of it I
I've had this long term issue in not quite understanding how to implement a

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.