3

I have DIV structure like this:

   <div id="wire" style="position: absolute">
    <div  style="position: absolute;background:white" ></div>
    <div  style="position: absolute;background:red" ></div>
    <div  style="position: absolute;background:white" ></div>
    <div  style="position: absolute;background:red" ></div>
    <div  style="position: absolute;background:white" ></div>
    </div>

I'm able to get all child div's in jquery like this :

$("#wire > div")

How to get all div's with white background only?

Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
Bharathi D
  • 953
  • 1
  • 15
  • 28

3 Answers3

2

You can use:

$("#wire > div[style*='background:white']")
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
1

Well... first of all you need to remove the inline style. See why. So you will have something like this:

CSS:

/*CSS*/
.absolute {position:absolute;}
.white {background: white;}
.red {background: red;}

HTML:

<!-- HTML -->
<div id="wire" class="absolute">
   <div class="white absolute"></div>
   <div  class="red absolute"></div>
   <div class="white absolute"></div>
   <div class="red absolute"></div>
   <div class="white absolute"></div>
</div>

And then simply do this:

$('#wire>div.white')
Community
  • 1
  • 1
John Skoumbourdis
  • 3,041
  • 28
  • 34
1

You can also use:

$("#wire > div").filter(function() {
    var $this = $(this);
    return $this.css("position") == "absolute"
    && $this.css("background-color") == "rgb(255, 255, 255)";
});
poh
  • 171
  • 9
  • D225
    D226
    D227
    D228
    this is my HTML code not working
    – Ragavan Jul 09 '14 at 09:20
  • see updated answer, background checking was wrong, you need to replace color value with it rgb, in this case: white = 255,255,255 – poh Jul 09 '14 at 09:38