JQuery gets children with the condition

I have a div with id='tips'. It has several children. What I need to do I want to get a child div with id='tips'which has its own style, top <10px. Here is a snippet of code.

<div id="tips">
   <div style="top: 5px; left: 150px;">
      Required Div
      <span class="arrow"></span>          
    </div>
   <div style="top: 15px; left: 150px;">
      Not-Required Div
      <span class="arrow"></span>          
    </div>
   <div style="top: 45px; left: 150px;">
      Child3
      <span class="arrow"></span>          
    </div>
</div>

There is only one div div div with a vertex <10px.

+3
source share
1 answer

Use filter():

var $child = $("#tips div").filter(function() {
    return parseInt($(this).css("top"), 10) < 10;
});

// you can do as needed with the element(s) here, this is just an example
$child.css("color", "#C00"); 

Script example

+6
source

All Articles