Get all elements with `position: fixed` in an HTML page?

The reason for this: I am debugging the css of my webpage. Some elements have appeared, and they should not appear. I suspect this is a problem with positioning elements. So I want to find these positioned elements and check one by one.

+4
source share
3 answers

This one uses jQuery. I hope you find it.

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

I think this works using 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])
    }

}
+7
source

Try the following:

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

He will give you all the items with a fixed position.

+1
source

document.querySelector('*[style="position:fixed"]')

* . [] , . , position:fixed.

jQuery, , , .

0

Source: https://habr.com/ru/post/1626300/


All Articles