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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:15:40+00:00 2026-06-18T08:15:40+00:00

I have a strange thing happening in my js script. When the click function

  • 0

I have a strange thing happening in my js script.

When the click function is executed, one element is supposed to be inserted below another one, but for some reason, the elements clone is inserted there as well.

How come? The cloning is happening outside the click function.

Pls help me understand what is going on.

http://jsbin.com/unenil/1/edit

$("button").click(function() {
  $(".one").insertAfter(".two");
  $(".status").text("done");
});


var clone_one = $(".one").clone();
var clone_two = $(".two").clone();
$("body").append(clone_one);
$("body").append(clone_two);

Basically I dont understand why the click function in this case has anything to do with the cloning which takes place outside of it.

  • 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-18T08:15:41+00:00Added an answer on June 18, 2026 at 8:15 am

    The cloned element has the one class, so his clone too.

    Therefore $(".one") contains both the cloned and the clone.

    A solution would be to keep a reference to the original element and to insert it :

    var original = $(".one");
    var clone_one = original.clone();
    var clone_two = $(".two").clone();
    $("body").append(clone_one);
    $("body").append(clone_two);
    
    $("button").click(function() {
      original.insertAfter(".two");
      $(".status").text("done");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CSS newbie here. Strange thing is happening, I have gaps between links, and I
I found a very interesting/strange thing about MAX() function in SQL. I have column
I have a strange thing happening with ABAddressBook. Here is some code: - (NSArray*)addressBookArray
I have this strange thing happening to my code. Using Firefox or Chrome (tried
I have an FBML app and a strange thing keeps happening. If I go
I have a strange thing happening with php files. As an example: domain.com/test.php domain.com/test
I have a strange thing happening while using ZedGraph . I am using the
I have a strange thing happening with my app now after iOS5 updates. I
I have noticed a strange thing happening in jQuery and wonder if anyone knows
Hi guys I have a very frustrating and strange thing happening here, when I

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.