0

I have a image-slider that slides a div with a new image in and sets the css attributes of the new div to display:block; and z-index:5;. It also sets the divs with the images that are not visible to display:none; and z-index:0;

I now want to add a class only to the current image-div that meets the condition z-index:5;

I have tried the following code but $(this) is not working and i dont have a clue how to only add a class that currently meets the condition.

if ($(".slides_control").children().css( "z-index", "5" )){
 $(this).addClass("test");
} else{
 $(this).removeClass("test");
}
<div class="slides_control">
Container div
   <div>div with the first image</div>
   <div>div with the second image</div>
   <div>div with the second image</div>
</div>
taikuri
  • 1
  • 4
  • `$(".slides_control").children().css( "z-index", "5" )` is setting the zindex not checking it. you want `$(".slides_control").children().css( "z-index" ) == "5"` (as a side note, you should know what type you return and not use ==. use === instead. read: http://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons) – rlemon Oct 14 '14 at 14:25

1 Answers1

2

You can just do this

var arr = $(".slides_control").children().filter(function() {
    return $(this).css("z-index") == "5"
}).addClass('test');
Amit Joki
  • 58,320
  • 7
  • 77
  • 95