Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created March 2, 2013 10:23
Show Gist options
  • Select an option

  • Save thinkphp/5070418 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/5070418 to your computer and use it in GitHub Desktop.
Event Delegation on CUI2 AMD Style
require(["ready","dom","delegate"], function(r, dom, d){
var ready = r.ready,
delegate = d.delegate;
ready(function(){
delegate(dom.select("#menu"), 'li a', 'click', function( e ){
var ul = e.target.parentNode.querySelector("ul")
if(ul.style.display == "none") {
ul.css("display: block")
} else {
ul.css("display: none")
}
if(window.console) console.log(e.target)
}, false);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment