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.. th
Try this:
var elements = $('*').filter(function () {
return this.style.position == 'fixed';
});
It will give you all elements having position fixed.
This one is using jQuery. I hope you are find with it.
var find = $('*').filter(function () {
return $(this).css('position') == 'fixed';
});
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])
}
}
document.querySelector('*[style="position:fixed"]')
The *
item specifies all tag names. The []
indicate that you're looking for an attribute. You want your style attribute to have position:fixed
.
If you aren't using jQuery, this is probably going to be your simplest option.
Here is an ES6 version that gives you an array of these elements for further processing:
let fixedElements = [...document.body.getElementsByTagName("*")].filter(
x => getComputedStyle(x, null).getPropertyValue("position") === "fixed"
);