Having difficulty getting fancybox options to show up only when my lightbox link has an id class in it. Here's what I have so far (which breaks it, and just goes straight to the image in a new page):
<script type="text/javascript">
var thisHash = window.location.hash;
$(document).ready(function() {
$(".fancybox").fancybox({
helpers : {
title : { type : 'inside' }
}, // helpers
beforeShow : function() { //Where my issue starts
if(typeof(this.element.attr("id")) !== 'undefined'){
this.title = (window.location + '#' + this.element.attr("id"));
}, // beforeShow
}); // fancybox
if (thisHash) {
$(thisHash).trigger('click');
}
}); // ready
</script>
Any suggestions? I thought filtering for "undefined" would do it, since when the id class is missing it normally returns "undefined" when I echo it, but maybe I'm just not using correct syntax for this since this is javascript and I've been dealing with PHP mostly.
an id class
? (maybe you meant anid
attribute) - JFK<a id="example1" class="fancybox" data-fancybox-group="example" href="path/to/image.jpg" title="image title">Image</a>
But in one section, I don't have links generated with an id, so i'd like to omit some details I add to a fancybox window if it doesn't detect an id tag. Interesting your fiddle works and its the same code, yet mine isn't working for me. - dotcommer