-1

I want from among the boxes that I put in the code below; Select a box whose z-index is equal to 3 and make its background red to distinguish it from other boxes.

html:

 <ul>
        <li class="post1">
            <div class="content">
                <h4 class="title">title post1</h4>
            </div>
        </li>

        <li class="post2">
            <div class="content">
                <h4 class="title">title post2</h4>
            </div>
        </li>

        <li class="post3">
            <div class="content">
                <h4 class="title">title post3</h4>
            </div>
        </li>

        <li class="post4">
            <div class="content">
                <h4 class="title">title post4</h4>
            </div>
        </li>

        <li class="post5">
            <div class="content">
                <h4 class="title">title post5</h4>
            </div>
        </li>
    </ul>

For this purpose I wrote a script code that does not work. Please edit this code for me:

script:

$("li").each(function(){
var a=$(this).find("li");
$(this).css('z-index',3);
a.style.background= "red";
});
Developer
  • 230
  • 8
  • If you know, that it is wrong, how have you tried to fix it? – Geshode Jan 17 '23 at 02:25
  • [How to select elements by CSS property value using JavaScript](https://stackoverflow.com/questions/52136305/how-to-select-elements-by-css-property-value-using-javascript) – Layhout Jan 17 '23 at 02:39
  • [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) – Layhout Jan 17 '23 at 02:40

1 Answers1

1

This should work

$("li").each(function(index){//goes througth li elements
if($(this).css("z-index") == 3){//if zindex equals 3
  $(this).css("background-color","red");//set back ground to red
}
});
yuta y
  • 144
  • 8