Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking for a css class on the nearest sibling() div with jQuery?

Is there a way in jQuery to return the nearest sibling() div and check for a present class?

I have a visual verticle list of items, in which some items either have a 1px border (to set them apart - premium items) or no border at all (standard items). While it looks great when a premium item is sandwiched between two standard items, when two or three premium items stack up the borders between them end up being 2px thick.

I'm looking for a way, using jQuery or otherwise, to check if the <div class="item"> above the current div has the class featured-item (so checking if the div equals <div class="item featured-item">). From there, I will set another class name to set border-top to 0px and make the visuals flow a little better.

Can anyone help me out? Sorry if this question is convoluted, hard to explain!

like image 815
Walker Avatar asked Mar 20 '26 05:03

Walker


1 Answers

if ($("#current-div").prev().hasClass("someClass")) {
  // logic here
}
like image 64
Fabian Avatar answered Mar 22 '26 18:03

Fabian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!