smtnkc
smtnkc

Reputation: 508

Getting position fixed elements using JS / jQuery

I am using a free hosting and the server creating some ads on page. I want to hide them with a js but they don't have a class or id. I have an idea but don't know it is possible or not.

The ads has position: fixed attribute and i don't have an element styled as fixed. So if I can hide fixed elements by use of JS, it solves my problem.

In this case I need some help on how to find position:fixed elements through JS. Thanks.

Upvotes: 0

Views: 112

Answers (3)

Venkata Krishna
Venkata Krishna

Reputation: 15112

This will hide all elements with position : fixed

$("*").filter(function() {
    return $(this).css("position") === "fixed";
}).hide();

Upvotes: 1

semirturgay
semirturgay

Reputation: 4201

try this :

  $('*').filter(function() {
        if($(this).css("position") === 'fixed'){
              $(this).hide();
         }
    });

Upvotes: 3

enguerranws
enguerranws

Reputation: 8233

You can do this, but it's really nasty :)

You have to search for elements that have a position:fixed, like that (with jQuery, I'm lazy):

$('body *').each(function() {
  if($(this).css('position') == 'fixed'){
    // Hide it the way you want (i.e. : $(this).css('display', 'none'); :)
  }
});

That will do the job, but that's not really clean.

Upvotes: 1

Related Questions