javascript - jQuery fancybox link inside div -
i have div containing information. wraped around div have 'a' tag when user clicks anywhere around div fancy box opens.
however inside div andother link when clicked instead of opening fancy box deleted whole div. used return false in click event delete worked.
i have had add .live click because newly created elemnet not getting click event.
since though when click delete link div delete fancy box opens also.
thanks help.
$(".listcontent").live('mouseenter', function(){ $(this).fancybox({ 'type':'ajax', }); }); $("div.removecompare").live("click", function() { $(this).parents(".listingcontainer").remove(); return false; });
div
<div class="listingcontainer grid_9 alpha omega"> <a class="listcontent" href="adcontent.html"> <div class="listingwrapper"> <div class="grid_8 alpha omega"> <div class="listingcontent"> <div class="imgholder"> <img src="imgs/cars/searchthumb-10053325.jpg" width="100" height="75"> </div> <div class="descholder"> <div id="cars"></div> <h3>fancy car</h3><div class="removecompare">remove</div> <p>lorem ipsum dolor sit amet, pri ex duis maiorum commune, illud viderer suscipiantur eam an. dolorum recteque qui in. pro inani nulla tacimates ex, qu</p> <span class="listingprice">€4,000</span> <span class="listingdate">listed: today</span> <span class="listinglocation">co. waterford</span> <span class="listingviews">viewed: 20 times</span> </div> </div> </div> <div class="goto goto_unfocus grid_1 alpha omega"> <div class="gotowrapper"> click view <div class="imgveiw"></div> </div> </div> </div><!--end listingwrapper--> </a> </div>
updated: this code should work.
$(".listcontent").live('click', function(e) { e.preventdefault(); $(this).fancybox({ 'type': 'ajax' }); console.log('inside fancybox creator'); }); $("div.removecompare").live('mousedown', function(e) { e.stoppropagation(); console.log('inside remove'); $(this).parents(".listingcontainer").remove(); });
i think problem event propagation
- when click on child element related event of parent fires up. e.stoppropagation()
stop that.
Comments
Post a Comment