Biswas Khayargoli
Biswas Khayargoli

Reputation: 1024

Find div which does not contain a specific property under specific attribute using CSS selector

I have the following situation:

<div id="foo">
   <div id="1" style="transform:translate3d(5px,5px,5px);"></div>
   <div id="2" style="background-color:black;"></div>
</div>

I want to find the div that does not have the 'transform' property i.e div with 'id = 2'.

I have tried the following, but it only selects the div having transform property, I want the exact opposite.

$('#foo').find('div[style*="transform"]');

Upvotes: 3

Views: 553

Answers (3)

Dalin Huang
Dalin Huang

Reputation: 11342

console.log($('#foo').find('div:not([style*="transform"])').text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<div id="foo">
  <div id="1" style="transform:translate3d(5px,5px,5px);">111</div>
  <div id="2" style="background-color:black;">222</div>
</div>

Upvotes: 2

Louay Hamada
Louay Hamada

Reputation: 771

this well do it

$('#foo div').not('div[style*="transform"]');

Upvotes: 3

guradio
guradio

Reputation: 15555

$('#foo').find('div:not([style*="transform"])').css('color','red')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="foo">
   <div id="1" style="transform:translate3d(5px,5px,5px);">1</div>
   <div id="2" style="background-color:black;">2</div>
</div>

  1. Use :not()

Upvotes: 7

Related Questions