javascript - 返回给定位置的元素(但它不是从该位置开始!)

标签 javascript jquery

我想返回具有给定左侧位置的元素。

假设我有以下内容:

<ul class="first" style="width:840px;left:-60px;"></ul>
<ul class="first" style="width:840px;left:0px;"></ul>
<ul class="first" style="width:840px;left:780px;"></ul>

我想返回left: 240px;后面的UL

var left = $('ul').filter(function() {
    return $(this).position().left == 240;
});
console.log(left);

我尝试了上述方法,但没有返回任何结果!

最佳答案

var behindsUL = $('.capture .captureButtons ul').filter(function() {
  var left = $(this).position().left;
  return left >= 240 AND left <= 280;
});
console.log(behindsUL);

如果存在诸如“&&”之类的 XML 语法冲突,您将不会走得太远...您应该找到解决方案

关于javascript - 返回给定位置的元素(但它不是从该位置开始!),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7188675/

相关文章:

javascript - 当 package.json 中包含版本 1.24.2 时,npm install 尝试安装 grpc 1.20.0

javascript - React State 没有按预期工作,有更好的方法吗?

javascript - 在特定断点处隐藏 DataTables 列

jquery - :not $(this) 的合适选择器是什么

jquery - 如何使用 bootstrap 和 booster 加载 jquery-1.11.2?

javascript - 为什么浏览器可以理解这个代码片段,但我的 typescript 编译器却不能?

javascript - addEventListener - 附加到文档与 document.body

javascript - 从文件中提取 AJAX

javascript - 为什么我不能进入我的 $document Ready 函数

javascript - 如果 jQuery 不存在,则使用 JavaScript 动态包含它