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?

6
  • possible duplicate of wildcard * in CSS for classes Commented Jan 9, 2015 at 2:25
  • @Antony That question is not the same as mine. In my case, I want to get all elements that matches with "1-<Just one character>" but I don't want get elements that matches with 1-* Commented Jan 9, 2015 at 2:34
  • How is that not the same? Commented Jan 9, 2015 at 2:36
  • You will have to do it the hard way then. Commented Jan 9, 2015 at 2:45
  • @Antony No way, these elements are generated dinamically. Commented Jan 9, 2015 at 2:47

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.