DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
    • can-construct-super
    • can-define-stream
    • can-fixture
    • can-fixture-socket
    • can-jquery
      • Modules
        • ./legacy
      • Methods
        • viewModel
    • can-stache-converters
    • can-stream
    • can-vdom
    • can-view-import
    • can-zone
    • steal-stache
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Ecosystem
  • /
  • can-jquery
  • / On this page
    • can-jquery

      module

      Extensions to the event system so that can events and jQuery events are cross-bound. Importing can-jquery will return the jQuery object and wire up the event system.

      var $ = require("can-jquery");
      
      var div = $("<div>");
      
      div.on("inserted", function(){
          // it inserted!
      });
      
      $("body").append(div);
      
      • npm package badge
      • Star
      • source

      jQuery

      Exports the jQuery object after setting up bindings between the event systems.

      Using can-jquery causes the two event systems to be cross-bound. You can listen to special events within can using jQuery and you can listen to custom jQuery events within can-controls.

      Listening to inserted/removed events

      Using can-jquery you can listen to the removed/inserted event on an element.

      var $ = require("can-jquery");
      
      var el = $("<div>");
      
      el.on("inserted", function(){
          // The element was inserted.
      });
      
      $(document.body).append(el);
      

      Listening to jQuery events within Controls

      Inside a can-control you can listen to any custom jQuery events.

      var $ = require("can-jquery");
      var Control = require("can-control");
      
      var MyControl = Control.extend({
          "names-added": function(el, ev, first, second, third){
              // first is "Matthew"
              // second is "David"
              // third is "Brian"
          }
      });
      
      var dom = $("<div><ul></ul></div>");
      
      new MyControl(dom);
      
      dom.find("ul").trigger("names-added", [
          "Matthew",
          "David",
          "Brian"
      ]);
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.