I would recommend you simplify your life a little by using CSS in combination with jQuery. In your CSS put this following. I have crafted this solution so it works as far back as IE6, but look at the end of my answer for a simpler solution that works in pretty much all browsers except IE6:
- div.product_img div.magnify { display: none }
- div.product_img_hover div.magnify { display: block }
And the new jQuery:
- $('div.product_img')
- .append('<div class="magnify"></div>')
- .hover(
- function() { $(this).addClass('product_img_hover'); },
- function() { $(this).removeClass('product_img_hover'); }
- );
- $('div.product_img div.magnify').live('click', function(){
- console.log('hello');
- $(this).trigger("myevent");
- // Make sure 'this' is what you want and
- // not $(this).closest('.product_img').trigger...
- }
If you don't care about IE6, then you can use straight CSS and even less jQuery:
- div.product_img div.magnify { display: none }
- div.product_img:hover div.magnify { display: block }
And the jQuery:
- $('div.product_img')
- .append('<div class="magnify"></div>');
- $('div.product_img div.magnify').live('click', function(){
- console.log('hello');
- $(this).trigger("myevent");
- }
You of course do not need to use `live` if you prefer a normal `click` event. The `live` had nothing to do with solving the problem.