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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:11:49+00:00 2026-06-02T19:11:49+00:00

I have 2 list with characters. I’m trying to make the old characters list

  • 0

I have 2 list with characters. I’m trying to make the old characters list updated with the new characters names in the li and html based on the data attribute value. when the Change List is clicked, so the final outcome looks like this:

//BEFORE
<ul id="new_characters">
<li id="peter"><div data="character1" class="character">Peter Griffin</div></li>
<li id="joe"><div data="character2" class="character">Joe Swanson</div></li>
</ul>

<ul id="old_characters">
<li id="glenn"><span data="character1" class="character">Glenn Quagmire</span></li>
<li id="louis"><span data="character2" class="character">Loius Griffin</span></li>
</ul>

<span id="change">Change List</span>

//AFTER
<ul id="old_characters"> //only this list should change on #change click
<li id="peter"><span data="character1" class="character">Peter Griffin</span></li>
<li id="joe"><span data="character2" class="character">Joe Swanson</span></li>
</ul>

Here’s a fiddle: http://jsfiddle.net/wXnSZ/

  • 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-02T19:11:52+00:00Added an answer on June 2, 2026 at 7:11 pm
    $('#change').click(function(){
        $('.character', '#new_characters').each(function(index, item){
            $(".character[data='"+$(item).attr('data')+"']", "#old_characters").text($(item).text());
        });    
    });​
    

    FIDDLE

    To replace the ID aswell, but keep the spans:

    $('#change').click(function(){
        $('.character', '#new_characters').each(function(index, item){
            $(".character[data='"+$(item).attr('data')+"']", "#old_characters").text($(item).text()).parent().attr('id', $(item).parent().attr('id'));
        });    
    });​
    

    FIDDLE

    or to change the complete html of each li in old_characters based on the data attribute:

    $('#change').click(function(){
        $('.character', '#new_characters').each(function(index, item){
            $(".character[data='"+$(item).attr('data')+"']", "#old_characters").replaceWith($(item).clone());
        });    
    });​
    

    FIDDLE

    or to just put the HTML of new_characters into old_characters:

    $('#change').click(function(){
       $("#old_characters").html($('#new_characters').html());
    });​
    

    FIDDLE

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

Sidebar

Related Questions

I have a list of html pages which may contain certain encoded characters. Some
I have a List<Data> that contains random objects: i and o characters. The Data
For example, I have an approved list of characters: a, b, and c. So
I have a question field with a list of allowed characters : A-Z,0-9,colon (:),
I have 2 collections of caracter string ex: List<string> one = new List<string>; one.Add(a);
I have a list with some Belgian cities with diacritic characters: (Liège, Quiévrain, Franière,
Suppose I have a list of strings where each string is exactly 4 characters
In a vim buffer if I have a list of characters say: A B
I'm trying to get a distinct list of characters (case sensitive) across all strings
Ok so let's say we have a linked list of characters with a head

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.