Note that there are some explanatory texts on larger screens.

plurals
  1. POHover event stops working after sorting divs
    text
    copied!<p>I'm working on an application which renders out images side by side. When hovering an image a hidden class is revealed showing information of the image.</p> <p>I also have a sort function so that one can sort the images by points (highest first, descending) instead of the default sort (date). Both hovering and sorting works fine, except for one thing.</p> <p>When the images is sorted by points and rendered out again, hovering the images doesn't work. I have looked at the generated code and it looks the same, but regardless that it doesn't work.</p> <p>I would really appreciate som help here, thanks!</p> <pre><code>&lt;div id="images"&gt; &lt;div class="image"&gt; &lt;div class="post"&gt; // other code here &lt;div class="postDesc"&gt; // other code here &lt;p class="postDescContent"&gt;Points: 10&lt;/p&gt; &lt;/div &lt;/div&gt; &lt;/div&gt; &lt;div class="image"&gt; &lt;div class="post"&gt; // other code here &lt;div class="postDesc"&gt; // other code here &lt;p class="postDescContent"&gt;Points: 20&lt;/p&gt; &lt;/div &lt;/div&gt; &lt;/div&gt; // and so one... &lt;/div&gt; </code></pre> <p>sorting function:</p> <pre><code>sortByPoints: function() { var contents = $('div#images div[class^="image"]'); contents.sort(function(a, b) { var p1= parseInt($('p.postDescContent', $(a)).text().replace('Points:','').trim()), p2 = parseInt($('p.postDescContent', $(b)).text().replace('Points:','').trim()); return p1 &lt; p2; }); var images = $('#images'); images.empty(); images.append(contents); } </code></pre> <p>hover function:</p> <pre><code>$('.image').hover(function () { $(this).find('.postDesc').toggle(); }); </code></pre>
 

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