This is truly bizarre. If I use jQuery's .find()
to find child elements that have data attributes during a scroll event, then scrolling the page will repeatedly add and remove an ID to the parents of those elements.
It's difficult to describe, but here's a reproducible test case: http://jsfiddle.net/8fouvx9p/
var groups = $(".group");
$(window).bind("scroll resize orientationchange", function() {
showGroup();
});
function showGroup() {
$(groups).each(function() {
var group = $(this),
elements = $(group).find("[data-animation]");
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="group">
<div data-animation="test" class="test">Test</div>
<p data-animation="test" class="test">Test</p>
<span data-animation="test" class="test">Test</span>
</div>
<div class="group">
<div data-animation="test" class="test">Test</div>
<p data-animation="test" class="test">Test</p>
<span data-animation="test" class="test">Test</span>
</div>
<div class="group">
<div data-animation="test" class="test">Test</div>
<p data-animation="test" class="test">Test</p>
<span data-animation="test" class="test">Test</span>
</div>
<div class="group">
<div data-animation="test" class="test">Test</div>
<p data-animation="test" class="test">Test</p>
<span data-animation="test" class="test">Test</span>
</div>
<div class="group">
<div data-animation="test" class="test">Test</div>
<p data-animation="test" class="test">Test</p>
<span data-animation="test" class="test">Test</span>
</div>
<div class="group">
<div data-animation="test" class="test">Test</div>
<p data-animation="test" class="test">Test</p>
<span data-animation="test" class="test">Test</span>
</div>
<div class="group">
<div data-animation="test" class="test">Test</div>
<p data-animation="test" class="test">Test</p>
<span data-animation="test" class="test">Test</span>
</div>
<div class="group">
<div data-animation="test" class="test">Test</div>
<p data-animation="test" class="test">Test</p>
<span data-animation="test" class="test">Test</span>
</div>
<div class="group">
<div data-animation="test" class="test">Test</div>
<p data-animation="test" class="test">Test</p>
<span data-animation="test" class="test">Test</span>
</div>
Make sure the preview is small enough that there's space to scroll, then inspect one of the "test" elements and scroll up and down. You'll see that in Firefox, it adds and removes an ID of null
to the test elements as you scroll:
In Safari, it happens less consistently – but when it does, the ID will start with sizzle
.
If I change the .find("[data-animation]")
to .find(".test")
, it doesn't happen.
Given the sizzle
ID that sometimes appears in Safari, I'm guessing this is due to an error in Sizzle (jQuery's selector engine) itself, and not something I'm doing incorrectly in my own code?