Why is this bookmarklet code saying jQuery is not defined even though jQuery is included?

Posted by Josh Brown on Stack Overflow See other posts from Stack Overflow or by Josh Brown
Published on 2010-05-30T04:57:31Z Indexed on 2010/05/30 5:02 UTC
Read the original article Hit count: 298

Filed under:
|
|

I am creating a bookmarklet and the code below is not working on first try. When I goto a page, it says "jQuery is not defined". But, if I click it again, it works perfectly?

var qrcodetogo = {
jQURL: 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js',
jQUIURL: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js',
jQUIThemeURL: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/ui-lightness/jquery-ui.css',
init: function(){
    this.createLink('qrcodetogo_UI-Lightness', this.jQUIThemeURL);
    this.createScript('qrcodetogo_jQuery', this.jQURL);
    this.createScript('qrcodetogo_jQueryUI', this.jQUIURL);
    this.createHiddenDiv('qrcodetogo_dialog','This is a Test.');
    jQuery.noConflict();
},

showQRCode: function() {
    jQuery('#qrcodetogo_dialog').dialog();
},

createLink: function(id, url) {
    var l = document.createElement('link');
    l.href = url;
    l.rel = 'stylesheet';
    l.type = 'text/css';
    l.media = 'screen';
    l.charset = 'utf-8';
    document.getElementsByTagName('head')[0].appendChild(l);
},

createScript: function(id, url) {
    var s = document.createElement('script');
    s.src = url;
    s.id = id;
    document.getElementsByTagName('head')[0].appendChild(s);
},

createHiddenDiv: function(id, body) {
    var div = document.createElement('div');
    div.id = id;
    div.innerHTML = body;
    div.style.display = 'none';
    document.getElementsByTagName('body')[0].appendChild(div)
}
}

qrcodetogo.init();
qrcodetogo.showQRCode();

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery