Jens Törnell
Jens Törnell

Reputation: 24748

How do I use a variable within a selector?

I'm having a problem with that variables in some cases are not set correctly.

@index: 10;
[data-grid*='cols-@{index}'] > * {
    background: red;
}

I use a variable index with the value of 10. I would expect the @{index} to be replaced with 10 but it doesn't. The result is [data-grid*='cols-@{index}'] and I don't get any errors.

Maybe I need to escape it somehow?

Upvotes: 2

Views: 104

Answers (1)

MarcoK
MarcoK

Reputation: 6110

You kind of answered your own question: You should treat the whole selector as a string. This seems to work:

@index: 10;
(~"[data-grid*='cols-@{index}'] > *")
{
    background: green;
}

Upvotes: 1

Related Questions