jqueryjquery-backstretch

Check if jquery plugin is loaded


How can I check if this jquery plugin backstrech was already loaded: http://cdnjs.cloudflare.com/ajax/libs/jquery-backstretch/2.0.4/jquery.backstretch.min.js

if($.fn.backstretch) is not working.


Solution

  • Looks like it works to me.

    Fiddle:

    backstretch_src = "http://cdnjs.cloudflare.com/ajax/libs/" +
                      "jquery-backstretch/2.0.4/jquery.backstretch.min.js";
    
    $(function init() {
        updateStatus();
        $('head').append($('<script>').attr('src', backstretch_src));
        setTimeout(updateStatus, 1000);
    });
    
    function updateStatus() {
        $('#status').text($.fn.backstretch ? 'Loaded' : 'Not loaded');
    }