javascript - Utilising .data() with FancyBox 2 -
i'm using fancy box 2 , trying use custom data inside .fancybox() call. below html:
<a title="test" data-album-id="5" class="fancybox" href="galleries/paris/originals/paris_001.jpg">'; and call:
<script> $('.fancybox').fancybox({ beforeshow: function () { alert($(this).data('album-id')); if (this.title) { // new line this.title += '<br />'; // add tweet button this.title += '<a href="https://twitter.com/share" class="twitter-share-button" data-count="none" data-url="' + this.href + '">tweet</a> '; // add facebook button this.title += '<iframe src="//www.facebook.com/plugins/like.php?href=http%3a%2f%2f'+'www.tommyreynolds.co.uk%2fgallery.php%3fgallery%3d'+ 5 +'%23image1'+'&width&layout=button_count&action=like&show_faces=true&share=true&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowtransparency="true"></iframe>'; } }, aftershow: function () { // render tweet button twttr.widgets.load(); }, helpers: { title: { type: 'inside' }, //<-- add comma separate following option buttons: {} //<-- add buttons }, closebtn: false, // use buttons arrows: false }); </script> but alert() on returns undefined. ideas?
instead of
alert($(this).data('album-id')); use
alert($(this.element).data('album-id'));
Comments
Post a Comment