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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:35:18+00:00 2026-06-03T10:35:18+00:00

var random1 = Math.floor((Math.random()*elems.length)); var random2 = Math.floor((Math.random()*elems.length)); while (random1 == random2) { var

  • 0
var random1 = Math.floor((Math.random()*elems.length));
var random2 = Math.floor((Math.random()*elems.length));

while (random1 == random2) {
    var random2 = Math.floor((Math.random()*elems.length));
}

$j('#project-scroller').append( elems );
$j('#project-scroller').append( elems[random1] );
$j('#project-scroller').append( elems[random2] );

So here’s what’s happening: elems gets appended but elms[random1] and elems[random2] doesn’t.

So then I tried this instead:

$j('#project-scroller').append( elems );
$j('#project-scroller').append( elems );

And elems was only appended once, that time, too! So then I tried this instead:

$j('#project-scroller').append( elems[random1] );
$j('#project-scroller').append( elems[random2] );

And both random elems were appended. Then I tried appending random1 twice, and it was only appended once…

What am I missing? Why won’t jQuery append the same elements more than once? Tried the same thing with appendTo (just for kicks), and it does the same thing.


Thanks for the answer! Here’s what I ended up with:

var random1 = Math.floor((Math.random()*elems.length));
var random2 = Math.floor((Math.random()*elems.length));
while (random1 == random2) {
    var random2 = Math.floor((Math.random()*elems.length));
}
newElem1 = $j(elems[random1]).clone();
newElem2 = $j(elems[random2]).clone();
$j('#project-scroller').append( elems ).append( newElem1 ).append( newElem2 );
  • 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-03T10:35:20+00:00Added an answer on June 3, 2026 at 10:35 am

    It’s not appending a copy of elems, it’s appending the real thing. Use clone() to create a 2nd copy to append.

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

Sidebar

Related Questions

var Rand1 = Math.floor(Math.random()*3); var Rand2 = Rand1; while ( Rand2 == Rand1 ){
this.randomtip = function(){ var length = $(#showcase ul li).length; var ran = Math.floor(Math.random()*length) +
var facebook_info = [{name:,url:}]; for(i=0;i<10;i++){ var randomNum = Math.floor(Math.random() * friend_list[0].fql_result_set.length); facebook_info[i].name=friend_list[0].fql_result_set[randomNum].name; facebook_info[i].url=friend_list[0].fql_result_set[randomNum].pic_square_with_logo; console.log(facebook_info.name[i]);
var swf=[1.swf,2.swf,3.swf]; var i = Math.floor(Math.random()*swf.length); alert(swf[i]); // swf[1] >> 2.swf This case ,Random
Here is the code I have written: function p_deal(id) { var card1_val = Math.floor(Math.random()
function randomize() { var ra = Math.floor(Math.random()*ar.length=4); document.getElementById('es').innerHTML = ar[ra]; } Is there a
I have the following code to generate two random numbers var attackRoll = Math.floor((Math.random()*6)+1);
$(function() { var number = document.getElementById(breuken); var i=0; for (i=1;i<=10;i++){ var fRandom = Math.floor(Math.random()*10);
I have the following function: var randomImages = [bgr1,bgr2,bgr3,bgr4,bgr5,bgr6]; var rndNum = Math.floor(Math.random() *
var dd = Math.floor(Math.random()*99); $('#a'+ dd + 'b'+ dd + 'c'+ d ).css({...}); for

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.