Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery append won't call twice?
    primarykey
    data
    text
    <pre><code>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] ); </code></pre> <p>So here's what's happening: elems gets appended but elms[random1] and elems[random2] doesn't.</p> <p>So then I tried this instead:</p> <pre><code>$j('#project-scroller').append( elems ); $j('#project-scroller').append( elems ); </code></pre> <p>And elems was only appended once, that time, too! So then I tried this instead:</p> <pre><code>$j('#project-scroller').append( elems[random1] ); $j('#project-scroller').append( elems[random2] ); </code></pre> <p>And both random elems were appended. Then I tried appending random1 twice, and it was only appended once...</p> <p>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.</p> <hr> <p>Thanks for the answer! Here's what I ended up with:</p> <pre><code>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 ); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload