I have created a custom base template like so:
baseTpl : '<div class="fancybox-container" role="dialog" tabindex="-1">' + '<div class="fancybox-bg"></div>' + '<div class="fancybox-inner">' + '<div class="fancybox-infobar">' + '<span data-fancybox-index></span> / <span data-fancybox-count></span>' + '</div>' + '<div class="fancybox-toolbar">{{buttons}}</div>' + '<div class="fancybox-navigation">{{arrows}}</div>' + '<div class="fancybox-stage"></div>' + '<div class="fancybox-social">' + '<button class="sharefb" title="Share FaceBook" data-share="hello"></button>' + '<button class="sharetwt" title="Share Twitter" data-share="hello"></button>' + '</div>' + '</div>' + '</div>',
How do I target the custom class sharefb? As I want to dynamically change the data-share attribute.
Thank you!
You event needs to be delegated, you will bubble the click event using a parent element, in my case the body:
$('body').on('click','.sharefb',function(){
$(this).attr('data-share','new value');
});
I found out that I can just do like this inside a fancybox instance inside opts:
afterShow : function( instance, current ) {
$('.fancybox-social .sharefb').click(function(){
//add your js here
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.