Removing random items,
<p>I have a static page that contains 10 images on the top of the page and 10 paragraps about those images later on the page. I randomly want to show 4 images (which I found the solution for) but I'm unsure how to match those to the text div coming later because I should hide/show the paragraphs about the image</p>

<p>the html:</p>

<pre><code>&lt;div id="images"&gt;
 &lt;div&gt;&lt;img src="img1"&gt;&lt;/div&gt;
 &lt;div&gt;&lt;img src="img2"&gt;&lt;/div&gt;
 ...
 &lt;div&gt;&lt;img src="img10"&gt;&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>and later on the page</p>

<pre><code>&lt;div id="text"&gt;
 &lt;p&gt;text about image 1&lt;/p&gt;
 &lt;p&gt;text about image 2&lt;/p&gt;
 ...
 &lt;p&gt;text about image 10&lt;/p&gt;
&lt;/div&gt;

randomElements = jQuery("#images div").get().sort(function(){ 
 return Math.round(Math.random())-0.5
}).slice(0,4)
</code></pre>

<p>To show the same paragraphs as the random images I have chosen I guess I should use the <code>:nth-child()</code> selector. But I have not been able to find out how to get the child number from the <code>randomElements</code>.</p>
