jQuery-design pattern
Table of Contents
#
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');
##bind event use on bind on parent selector
$('ul').on('click', 'li', function () {
// dosomething
});