在HTML页面中获取“position:fixed”的所有元素? [英] Get all elements with `position:fixed` in an HTML page?

查看:149
本文介绍了在HTML页面中获取“position:fixed”的所有元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这样做的原因:我正在调试我的网页的CSS,一些元素出现,不应该出现。我怀疑这是元素定位的问题。因此,我想找到这些定位元素并逐一检查。

Reason for doing that: I'm debugging css of my webpage.. some elements appeared and they're not supposed to appear. I suspect it is the issue with element positioning.. therefore I want to find these positioned element and check one by one.

推荐答案

这一个是使用jQuery。我希望你能找到它。

This one is using jQuery. I hope you are find with it.

 var find = $('*').filter(function () { 
        return $(this).css('position') == 'fixed';
    });

我认为这个工作使用纯粹的javascript:

I think this one works using a pure javascript:

var elems = document.body.getElementsByTagName("*");
var len = elems.length

for (var i=0;i<len;i++) {

    if (window.getComputedStyle(elems[i],null).getPropertyValue('position') == 'fixed') {
        console.log(elems[i])
    }

}

这篇关于在HTML页面中获取“position:fixed”的所有元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆