在位置为top大于指定位置的myClass类的html文档中查找第一个元素的最佳方法是什么
最佳答案
错误(第一个答案):
var $elm = jQuery.each($('.myClass'), function() {
if ($(this).attr('top') > x) return $(this);
});
好 :
var $elm;
jQuery.each($('.myClass'), function() {
if ($(this).attr('top') > x) {
$elm = $(this);
return false;
}
});
此解决方案不解析所有
.myClass
元素,仅返回第一个元素并停止。