开发者

jQuery toggle div with link to colorbox (lightbox)

开发者 https://www.devze.com 2023-01-30 16:23 出处:网络
I have a div that toggles the visibility of the list below it.Within that main div, I have a link that opens a colorbox (jquery \"lightbox\" plugin) to add a new item to the list.

I have a div that toggles the visibility of the list below it. Within that main div, I have a link that opens a colorbox (jquery "lightbox" plugin) to add a new item to the list.

Of course, when I click the link, it doesn't do anything but toggle the list (like its parent). So I added the stopPropagation() to the link. It does follow the link now, but it opens in the parent window instead of in the colorbox.

How do I fix this? Thank you :)

<div class="list">
<div class="listname">
My List Name
<a href="my_link.html" class="colorbox">Add Item</a>
</div>
<div class="items">
My Items
</div>
</div>

$(".listname").toggle(
 function(){
  $(this).siblings(".items").slideDown(100);
  return f开发者_C百科alse;
 },
 function(){
  $(this).siblings(".items").slideUp(100);
  return false;
 }
);

$(".listname a").click(function(e){ e.stopPropagation();  });


Not sure exactly without knowing exactly what the lightbox trigger is but have you tried adding

event.preventDefault();

to prevent the following of the link?

$(".listname a").click(function(e){ 
    e.stopPropagation();
e.preventDefault();
});


Ensure you have required Jquery Library before Colorbox script

<script src="/js/jquery.js" type="text/javascript">
<script>
 jQuery('a.colorbox').colorbox();
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消