Wednesday, March 02, 2011

jQuery modal not working when inside click function

It seems that every time I want to do something new, I am faced with learning/figuring out a new library or technology. This time it was jQuery and boy I was having some problems with it.

One of the issues I was facing was with this code, where I wanted to show a modal 'pop up' when an image was clicked. The 'modal' command worked fine, except that it refused to work when called from inside a 'click' function.

If anyone knows how to make this work I'd love to know.

//works on its own
jQuery('#takeidphoto').modal({position: [160,160]});

//totally doesn't work
jQuery('#takephotoimg').click(function() {
jQuery('#takeidphoto').modal({position: [160,160]});
});


In the end I resorted to plain old javascript and used this decent library from Matt Kruse called 'DIV Popups' which served my purpose: http://www.javascripttoolbox.com/lib/popup/example.php

No comments:

Post a Comment