I would like to get all elements (all divs) in a page with CSS property position:fixed;
and remove or change that property.
Is that possible with JavaScript / jQuery?
I would like to get all elements (all divs) in a page with CSS property position:fixed;
and remove or change that property.
Is that possible with JavaScript / jQuery?
Yes, it's possible. You can select the div
elements using document.querySelectorAll
method and then filter the elements that have fixed position:
[].forEach.call(document.querySelectorAll('div'), function(el) {
if (window.getComputedStyle(el).position === 'fixed') {
// el.style.position = 'relative';
}
});
Yes you can do it with jquery each() and css() functions :
Js code :
$('div').each(function(){ //loop over all the divs
//Condition for the div with style propriety position:fixed;
if($(this).css('css('position')=="fixed"){
//Do the change you want
}
})
It can certainly be done, just not very efficiently. @Vohuman implements this nicely in plain javascript. I recommend taking a look at this similar post which has answers that are implemented in jQuery as well Select all elements that have a specific CSS, using jQuery
you have to get all elements in a node collection with the method "querySelectorAll" likes this:
var divCollection = document.querySelectorAll('div');
Then you have to check with a loop for the element state like this:
for(var i=0; i<divCollection.length;i++){
var elementState = $(divCollection[i]).css('position');
console.log(elementState);
}