Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!