2

I have the following elements:

<div customAttribute="1" > element 1 </div>
<div customAttribute="1-1" > element 1-1 </div>
<div customAttribute="1-1-1" > element 1-1-1 </div>
<div customAttribute="1-1-2" > element 1-1-2 </div>
<div customAttribute="1-2" > element 1-2 </div>

How can I get the all elements with the customAttribute

1-1,
1-2,
...
1-n

but not

1-1-1,
1-1-2,
...
1-1-n

with a CSS selector?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Cristhian Boujon
  • 4,060
  • 13
  • 51
  • 90

1 Answers1

4

As far as I understand you could use div[customAttribute^='1-']:not([customAttribute^='1-1-']). This will work with both jquery and css as you could see: http://jsfiddle.net/597y2e6r/1/

If that is not the case you need more complex pattern matching css might not be the best tool ... you could use filter instead.

alexanderg
  • 177
  • 1
  • 9
  • If there are `1-2-n` elements and `1-n-n` elements, then there's no other way than to repeat as many `:not()`s as necessary. The filter route would be best, if not modifying the HTML somehow. – BoltClock Jan 09 '15 at 05:21