Skip to content

Instantly share code, notes, and snippets.

@mklabs
Created November 18, 2010 10:20
Show Gist options
  • Select an option

  • Save mklabs/704835 to your computer and use it in GitHub Desktop.

Select an option

Save mklabs/704835 to your computer and use it in GitHub Desktop.
Example of what not to do when writing jQuery code (well it begins by following js is a hack... pretty explicit...)
// the following javascript is a hack to display a "file" image instead of a "folder" image
// when an entity has no children to display.
var ulList = $('ul');
for (i=0; i<ulList.length; i++) {
var ulEl = ulList[i];
if ($('li[class!=liToHide]', ulEl).length == 0) {
var spanEl = $(ulEl).prev().prev();
var imgList = $('img', spanEl);
$(imgList[0]).attr('src', Constants.LI_IMG_URL);
$(imgList[1]).attr('src', Constants.FILE_IMG_URL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment