1

I suspect that jQuery is not working ok in my extension... I'm using version 1.3.2, loaded with the following rows:

var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
              .getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://myext/content/lib/jquery.js", myext);

My problem is that, when running the following rows, the one tagged as 1 works, the 2 raises a misterious error "L is null" related to jQuery:

jQuery.noConflict();
$ = function(selector,context){ return new jQuery.fn.init(selector,myext.doc); };
$.fn = $.prototype = jQuery.fn;
$().ready(function() {
   $("menuitem#a").attr("label","Value set by jQuery!");             // 1
   $("menupopup#listacorsi").append("<menuitem label='newnode!'/>"); // 2

});

I supposed that second row should be good to add a child node to element #listacorsi. menuitem#a is a child of #listacorsi. Could you please help me to understand what's wrong with my coding?

Thanks and best regards,

Livio

Tobu
  • 24,771
  • 4
  • 91
  • 98
liv913
  • 117
  • 9
  • Personally, I had only problems with jQuery and Firefox extensions. This might get better with JetPack. If you only do basic DOM manipulation, you can go without jQuery. You have to deal with Firefox only anyway so cross-browser issues are not your concern. – Felix Kling Sep 19 '10 at 08:23
  • When I need to use jQuery on a site that *may* already have it, I test for its existence first, before loading a possibly older version. You can check $.jquery for the version number in recent versions. In my case, I also write jQuery that I know is compatible with jQuery 1.0 where possible, in case the website uses a very old verison. – mkoistinen Sep 19 '10 at 08:23
  • Quite possibly related: http://stackoverflow.com/questions/491490/how-to-use-jquery-in-firefox-extension – Tyler Sep 19 '10 at 16:57

1 Answers1

0

You should be referencing $ variable like this:

$("body",window.content)

Also I have also used jQuery in my firefox extension it works seamlessly with no issues at all.

Meher Ranjan
  • 157
  • 7