Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

91
Visualizações
Jquery hiding elements with specific classname that do not match a certain condition

I have a page which has multiple elements that all have the same classname.

Some of them are being repositioned and when I submit the page I would like to hide the elements which are at a position of top: 0;

I've been looking at some suggestions and I've tried something like this:

$('.myClass').not($('.myClass').css('top', '0')).fadeOut(300);

But appearantly that's not working :-)

Anybody else has an idea on how to accomplish this?

Thanks

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You are setting the position top of the elements, not filtering the set.

You want to use filter()

$( '.myClass' )
  .filter(function() {
    return $(this).css('top') === "0px";
  }).fadeOut(300);
about 4 years ago · Santiago Trujillo Relatório

0

There is no selector for this but this can be accomplished with by looping the elements and checking for the top position.

Something like this.

$.each($('.myClass'), function(i, el) {
  var position = $(el).position();

  if (position.top === 0) {
      $(el).hide();
  }
});

Here's a fiddle

about 4 years ago · Santiago Trujillo Relatório

0

Loop over every element with the class then check for its css property:

$('.myClass').each(function(){
  if($(this).css('top')==='0'){
     $(this).fadeOut(300);
  }
});
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda