So then this behaviour is working because I'm using a live handler? In this case I am indeed using a live handler because elements of the thumbnail class don't exist when the document is initially created, but are conditionally added at a later point.
I'm reasonably sure that this is an appropriate use for a live handler. But didn't expect such usage to have the consequences that I am seeing. I'm obviously taking a wrong approach here, based on limited knowledge. Can you suggest another approach ? I'm looking at the docs for livequery at the moment. http://docs.jquery.com/Plugins/livequery Perhaps I should use that instead ? On Apr 11, 1:44 pm, jay <jay.ab...@gmail.com> wrote: > A live handler is different from a normal handler, and I'm not sure > why you're putting a normal handler inside of a live handler. A live > handler works by looking at the target of whatever is clicked and > comparing it to the selector, in this case, the thumbnail class. I > personally prefer to use live handlers for content that is added and > removed dynamically since it is easier to manage. > > On Apr 10, 9:30 pm, thought <thou...@orcon.net.nz> wrote: > > > Thanks for the swift replies. > > > I've got a lot to learn about javascript, and at this point, adapting > > charlies code, I get a strange effect that I didn't anticipate, and > > don't understand. > > > $('.thumbnail').live("click", function(){ > > > $("div[id^='thumbnail']").click(function() { > > alert( $(this).attr('id') ); > > > }); > > > For the first time I click on a div, I get nothing. No alert. > > For the second time I click a div, the alert pops up a couple of > > times. > > For the third time, the div pops up multiple times - displaying the > > id, and then displaying the name of the class. > > > I'm guessing that I'm encountering something about js that I don't > > understand. > > If someone were to give me a pointer that explains this behaviour, and > > how to change it I'd be grateful. > > > Thanks.