-1

I include a mixins into my scss file like this :

.element{
    @include putOnCircle(2, 20em, 6em, false);
}

But instead of having the "2" parameter, I need to get this value directly from my html page. Maybe, I can use data-value :

<div class="element" data-value="2"></div>

And get the value with attr(). Then I could replace the "2" parameter by attr(data-value) for exemple.

It doesn't really work, and I wonder if it's possible to do such a thing.

I don't want to use jQuery just for that, nor define each .element[data-value=""] possible.

If you have any idea, I'll take it.

Thanks for your help.

Geetix
  • 155
  • 1
  • 2
  • 13

1 Answers1

1

While a few things in CSS can read attribute values (such as attr), there isn't very much you can do with them, and you certainly can't get them into a SASS function.

SASS is compiled into CSS by a preprocessor and doesn't have access to any of the HTML documents that the compiled CSS might be applied to in the future.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • I already know, I just need to know if there is a workaround to do what I want ? Not necessarily with sass, but just with css maybe. – Geetix Sep 02 '15 at 07:09
  • With CSS: probably not, but since your question doesn't give any clue as to what you are trying to achieve with the CSS (i.e. what you want to do with the value), it is hard to say for certain. – Quentin Sep 02 '15 at 07:10
  • I understand, this value is using into the mixins to make certain calculation. It's the number of languages in my database just for information. – Geetix Sep 02 '15 at 07:27
  • It isn't possible to tell you how (or if) you can replicate *mysterious unspecified SASS calculation* in CSS. You need to step back and explain the actual problem, not a piece of the solution that you don't like. – Quentin Sep 02 '15 at 07:30
  • But this has nothing to do with what I want to do .. I just need to get this value from my html file that's all. At worst, if you know how to do with jQuery why not, but I would prefer with css (or sass) – Geetix Sep 02 '15 at 07:34
  • It isn't possible to do it with SASS. You haven't told us enough about what the SASS is doing in order to tell if you could achieve the same thing with CSS or with JavaScript. You certainly can't use JavaScript or CSS to insert a value into a SASS mixin because that mixin will have been executed long before anything processes the CSS or JavaScript. – Quentin Sep 02 '15 at 07:35
  • I use http://codepen.io/HugoGiraudel/pen/Bigqr you can find the mixin inside – Geetix Sep 02 '15 at 09:19