Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes JQuery "cache" DOM elements? Or is it Chrome?
    primarykey
    data
    text
    <p>I'm writing a small Chrome extension to manipulate Google's search results' DOM to add a small set of questions to ask the user why s/he chose to follow that link; while polishing, I decided to look around the page in case there was an old poll already shown, to remove it (as in, if the user decided to follow another result after s/he clicked on one), and that's when I started noticing a weird behaviour: the first time I clicked a link I got presented the poll before being able to proceed to the chosen page; the second time (without leaving the page) the old poll got correctly removed and the new one added to the DOM, but this new element got targeted by <code>slideDown()</code> only if it was inserted <em>before</em> the old one (i.e. if I clicked a link <em>above</em> the previous one).</p> <pre><code>$('li.g a') // all the results' link .bind('click', function(event) { event.preventDefault(); // avoid going to destination right away var oldpoll = $('#extension'); if (oldpoll.length) oldpoll.slideUp('fast', function(){ $(this).remove(); }); // remove (eventual) old poll ... $(this).parents('.g').append(element); $('#extension').slideDown(); }); </code></pre> <p>As you can see, I figured there was some sort of caching going on and tried to "force" avoiding it by declaring a variable to hold the old element, but that didn't work; eventually, I managed to sail around it by forcing a new DOM traversal with <code>$('#extension a').parent().slideDown();</code>, but now I'm really curious about whether it's my fault, or Chrome's, or JQuery's. Thanks.</p>
    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.
    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