I'm making a style guide and I have disabled css in pre markup that I'm trying to apply as valid css to example boxes above.
Easier to understand with markup (please don't mind the weird indentation, it's done on purpose to simplify rendering. Also "defaut" is the french word for "default") :
<div id="styleguide" class="field-style">
<div class="colored">
</div>
<pre><code class="language-less">
@defaut: #000;
</code></pre>
<div class="colored">
</div>
<pre><code class="language-less">
@defaut: #e55240;
</code></pre>
<div class="colored">
</div>
<pre><code class="language-less">
@defaut: #fff;
</code></pre>
</div>
I tried several variations but it doesn't work. Here is my latest attempt. In here I'm trying to select via regex everything up to and including '#', and delete it. Then I get the numbers and put them in background style. You could say I should filter directly to only select numerical values via regex, but it didnt't work either and I don't know why
$('.field-style .colored').each(function() {
var $this = $(this);
$this.css(
'background', '#' +
$this
.next('pre')
.children('code')
.text()
.replace('/^(.*?\\#)|;/', '')
);
defaultis spelled incorrectly?:character, then you know [0] is the attribute (if it starts with @ you could easily know its a special one) and use [1] as the value? So...$(this).css('background', $(this).next().children('code').text().split(':')[1].trim())That method makes it easier to apply later as well, as you could use [0] as the attribute if thats defined or something...