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

  • Home
  • SEARCH
  • 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 7797281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:38:14+00:00 2026-06-01T23:38:14+00:00

I would like to replace the innerhtml of thisOne with that of either clone1

  • 0

I would like to replace the innerhtml of thisOne with that of either clone1 or clone2.

I have figured out how to replace the entire thisOne element with that of the clone, but would rather not do it that way as I store data in the li element.

I also have figured out how to put a separate div tag around the clones innerhtml, clone(true) that redundant tag element, and append the redundant tag and its innerhtml into thisOne, but these seems like a waste of a tag.

I also find that html() doesn’t bring over the events, and would rather not re-declare them each time I swap the html.

Any suggestions? Thank you

<ul>
<li id="thisOne" data-attr="whatever"></li>
</ul>

<ul style="display: none">
<li id="clone1">
<a href="#" class="doSomething1">Click</a>
<button class="doSomething3">Click</button>
</li>
<li id="clone2">
<a href="#" class="doSomething2">Click</a>
<button class="doSomething4">Click</button>
</li>
</ul>

....

$("clone1 a").click(function(){alert("hi");});

The following new code added doesn’t appear to work.

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Dialogs</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js" language="javascript"></script>
<script type="text/javascript">
$(document).ready(function(){    
    $("#cloneIt").click(function(){$('#newLocation').html($('#clone').html());});
    $("#clone a").on("click", function(){alert("click");});
    $("#clone select").on("change", function(){alert("change");});

});
</script>

</head>
<body>
<input type="button" value="Clone it" id="cloneIt" />

<div id="newLocation"></div>

<div id="clone" style="display: none">
<a href="#">Click Me</a>
<select><option>Hello</option><option>Goodby</option></select>
</div>

</body>
</html>
  • 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-01T23:38:16+00:00Added an answer on June 1, 2026 at 11:38 pm

    you can iterate children, than append cloned each one to thisOne

       $("#clone1, #clone2").each(function() {
            $(this).children().each(function() {
                    $("#thisOne").append($(this).clone(true));
            });
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable myvar = document.getElementById('myid').innerHTML that I would like to replace all
I would like to replace drop down list (that has on change event that
I have such file and I would like to replace $GLOBALS['SERVER_MEMCACHED']='localhost'; with $GLOBALS['SERVER_MEMCACHED']='mydomain.com'; using
I have the following table and would like to replace the string text of
I have this sample string where I would like to replace the star with
I have a UIImage with white background. I would like replace the white background/pixels
I would like to replace strings that starts with [id, has a middle part
I would like to replace . by , in a String/double that I want
I would like to replace a text of aliasname element with a text from
With a string like HorsieDoggieBirdie, is there a non-capturing regex replace that would kill

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.