Search code examples
javascriptjqueryfancyboxconcrete5

check if rel=group exists for fancybox using jquery?


I have the following code in my page:

<script type = "text/javascript">
$(document).ready(function() {
    // Fancy LightBox
    $("a[rel=group]").fancybox({
        'transitionIn'      : 'elastic',
        'changeFade'        : 'fast',
        'transitionOut'     : 'elastic',
        'titlePosition'     : 'over',
        'overlayOpacity'    : '0.6',
        'showCloseButton'   : false,
        'overlayColor'      : '#000000',
        'titleFormat'       : function(title, currentOpts) {
                return '<span id="fancybox-title-over">'+ (title.length ? ' &nbsp; ' + title : '') + '</span>';
            }
    });

});
</script>

But when there is not an element with rel=group it crashes my Concrete5 dashboard panel. Is there a way to check if the element with rel=group exists and if it does not, DONT fire the code?


Solution

  • Try

    if($('a[rel="group"]').length > 0)
    {
        $('a[rel="group"]').fancybox({