I'm trying to get the data-shareurl from the link below for use in jQuery but for some reason when I put the variable into an alert it is always undefined. Can anyone tell me what I've got wrong? Thanks. I've made a fiddle here
Html
<a title="" class="fancybox" data-shareurl="www.google.com" href="http://fancyapps.com/fancybox/demo/1_b.jpg">
<img src="http://fancyapps.com/fancybox/demo/1_b.jpg" title="" /></a>
jQuery
var shareurl = $(this).attr('data-shareurl'); //Get this url
$(".fancybox").fancybox({
beforeShow: function() {
this.title = '<div class="addthis addthis_toolbox addthis_default_style "><a href="' + this.href + '" addthis:url="' + this.href + '" addthis:title="' + this.title + '" class="addthis_button_preferred_1"></a></div>';
alert(shareurl); //see the variable
},
afterShow: function() {
addthis.toolbox(
$(".addthis").get()
);
},
helpers: {
title: {
type: 'inside'
}
}
});