반응형
    
    
    
  Caching jQuery selections in an object
Before
jQuery(document).ready(function() {
jQuery('#some-selector').on('hover', function() {
jQuery(this).fadeOut('slow').delay(400).fadeIn();
console.log(jQuery(this).text());
});
jQuery('#another-element').on('hover', function() {
jQuery(this).slideUp();
});
jQuery('#some-selector').on('click', function() {
alert('You have clicked a featured element');
}); 
jQuery('#another-element').on('mouseout', function() {
jQuery(this).slideUp();
});
}); 
After
var someNamespace_Dom = {
 someSelector : 'jQuery("#some-selector")',
 anotherElement: 'jQuery("#another-element")',
};
jQuery(document).ready(function() {
 someNamespace_Dom.someSelector.on('hover', function() {
  jQuery(this).fadeOut('slow').delay(400).fadeIn();
  console.log(jQuery(this).text());
 });
 someNamespace_Dom.anotherElement.on('hover', function() {
  jQuery(this).slideUp();
 });
 someNamespace_Dom.someSelector.on('click', function() {
  alert('You have clicked a featured element');
 }); 
 someNamespace_Dom.anotherElement.on('mouseout', function() {
  jQuery(this).slideUp();
 });
}); 
반응형
    
    
    
  '프로그래밍 > Script' 카테고리의 다른 글
| [jQuery] 16 Free jQuery Data And Time Plugins (0) | 2013.08.12 | 
|---|---|
| JavaScript: an overview of the regular expression API (0) | 2013.08.08 | 
| [javascript] Pickadate.js — Responsive date & time picker (0) | 2013.08.07 | 
| [jQuery] Sticky-kit: A sticky element jQuery plugin (0) | 2013.08.07 | 
| [WEB] HTML5, CSS, javascript 게임 (0) | 2013.08.06 | 
