翻译:Terry li - GBin1.com
英文: 50 jQuery Snippets That Will Help You Become A Better JavaScript Developer
1. 创建一个嵌套的过滤器
.filter(":not(:has(.selected))") //去掉所有不包含class为.selected的元素
2. 重用你的元素查询
var allItems = $("div.item"); var keepList = $("div#container1 div.item"); <div>class names: $(formToLookAt + " input:checked").each(function() { keepListkeepList = keepList.filter("." + $(this).attr("name")); }); </div>
3. 使用has()来判断一个元素是否包含特定的class或者元素
//jQuery 1.4.* includes support for the has method. This method will find //if a an element contains a certain other element class or whatever it is //you are looking for and do anything you want to them. $("input").has(".email").addClass("email_icon");
4. 使用jQuery切换样式
...
...
原文出处:
分享50个使你成为高级javascript开发者的jQuery的代码开发技巧 - 第一部分
分享50个使你成为高级javascript开发者的jQuery的代码开发技巧 - 第二部分