$("img").mouseover() $("img").mouseover() window.setInterval(function() {
$('img').mouseover();
}, 500);
So you can catch the ones that haven't been created yet. var event = document.createEvent("MouseEvent");
event.initMouseEvent("mouseover", true, true, window);
function save_them_prontos(){
var ims = document.getElementsByTagName('img');
for(var i=0;i<ims.length; i++){
if(ims[i].id == ''){
ims[i].id = i;
ims[i].dispatchEvent(event);
}
}
time_dem();
}
function time_dem(){
window.setTimeout(function(){
save_them_prontos();
},100)
}
save_them_prontos();
triple :(Same, but nicer, listens to mouseover events on img elements that may not exist yet. Then again, this will - if I understand correctly - cause the event to bubble up in the DOM until it reaches the root element, where jquery's live callback handler will check what element the event took place on and invoke that callback.
$(document).on('mouseover', 'img', function() {});
You want to trigger the mouseover event, not bind to it. And you want to trigger it after the image has been inserted. Unfortunately there's no jquery event for dom insertions. But on firefox you can use a MutationObserver:
MutationObserver(function(event) {
$(event[0].addedNodes[0]).mouseover();
}).observe($('body')[0], {childList: true}); var evt = document.createEvent("MouseEvent");
evt.initMouseEvent("mouseover", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
function isALemming(node) {
return node.nodeName === 'IMG';
}
function fakeMouseover(node) {
node.dispatchEvent(evt);
}
function saveLemmings(possibleLemmings) {
possibleLemmings.filter(isALemming).forEach(fakeMouseover);
}
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(record) {
saveLemmings(Array.prototype.slice.call(record.addedNodes || []));
});
});
saveLemmings(Array.prototype.slice.call(document.getElementsByTagName('img')));
observer.observe(document.body, { childList: true });double :(
I read it as the first, and had this immediate reaction:
- I'd rather write the 1 line of jQuery over the 6 in vanilla javascript
- I'd rather read the 1 line of jQuery to understand what is going on instead of the 6 in vanilla javascript
- jQuery didn't actually impact your experience much... as you didn't realize it might even be available.