Stefan
Stefan

Reputation: 137

CSS Selector Syntax for nested bracket expressions

How can I select the following (which is created by jquery validate)?

<label class="error" for="location[]">...</label>

The CSS Selector

.error[for=location[]] 

does not work neither

.error[for=location] 

Upvotes: 1

Views: 500

Answers (2)

Ankur Aggarwal
Ankur Aggarwal

Reputation: 3101

You need to put attribute value in quotes in selector

.error[for="location[]"]
{
    color:red;
}

JSFiddle: http://jsfiddle.net/TQ2nN/

Upvotes: 3

Hashem Qolami
Hashem Qolami

Reputation: 99484

You can wrap the attribute value by quotes " as:

.error[for="location[]"]

Or use a leading back-slash \ to escape the brackets as:

.error[for=location\[\]]

However, you can also use the attribute selector as for^=location.

Upvotes: 2

Related Questions