Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

While I was working on a jQuery UI plugin I'm writing, in my haste to get it going I made a simple mistake, which was forgetting the fundamental principle of how jQuery works with it's selectors. My aim was to create a new Image instance, apply my jQuery UI plugin to it, which wraps that image in a DIV and then add the DIV to the DOM.

My plugin id is 'photoboxr' and so my code looked something like this...
 JavaScript
var div = $('img').photoboxr({...plugin options...}).photoboxr('wrapper');
$(document).append(div);


Seems simple enough but nothing worked and instead I got a lot of flickering when my web page loaded. I was confused at first.

Then, I realised that I was doing this: $('img'). The intent was of course to create a new Image node, but the reality of running that was to select all existing 'img' elements in my web page. The rest of the code then applied my plugin to all those images and hence caused the flickering and the same repeating image all over the place.

That was a big oops! In case my explanation above is not clear, jQuery was simply interpreting my code by running its Element Selector.

The fix is easy, create a new Image HTML object and pass that to jQuery instead. Derp. The code now became..
 JavaScript
var div = $(new Image()).photoboxr({...plugin options...}).photoboxr('wrapper');
$(document).append(div);


After that everything worked perfectly! Simple mistake, but easy to fall for.



-i

Please leave your comments or feedback below!
comments powered by Disqus
Other posts you may like...
Hi! You can search my blog here ⤵
Or browse the recent top tags...

Recent Blog Posts

Mini review of the Sonoff B1 WiFi light bulb

Coherence cache performance optimistic vs replicated schemes

Coherence and weblogic.xml in different types of J2EE web app deployments

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 1 - introduction and case disassembly

jPhotoFrame updated to version 0.3.1 with an image rotation correction utility

iOS 11 pre-GM mini review before it gets revealed next week

Recent Galleries

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 1 - introduction and case disassembly

Building a custom Atari Lynx game box storage shelf unit in a day

Protecting old Atari Lynx game boxes with snug fit plastic sleeves

Monument Valley 2 is released and does not disappoint

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity