on 2013-08-08

modulize

  • modulize selector
var module = $('body');
module.on('click', 'a', function() {
		// dosomething...
});
  • initialize
if ($('body').length) {
		// dosomething
}

selector

id is better than tag and class

HTML

<div>
    <ul>
    	<li id="id" class="class">text</li>
    </ul>
</div>

JavaScript

$('#id').html();
$('body').find('#id');

jsperf

##bind event use on bind on parent selector

$('ul').on('click', 'li', function () {
	// dosomething
});

js Bin