I have an idea, and I'm not entirely sure that the interpreter is incapable of handling this already, yet I am sure it does not. Therefore, my question is, does the interpreter already handle the idea I am about to propose.
Esentially, what I would like to do, is nest a block of Javascript into various locations of a stylesheet. The Javascript block should be able to access the scope of the CSS block which it is nested within. Maybe a sample code block would make this a little more clear.
.page {
<script>
target.header = document.createElement('div');
target.header.className = 'pageHeader';
target.header.heightPerc = 0.2;
target.header.widthPerc = 1;
target.header.height = target.clientHeight * target.header.heightPerc;
target.header.width = target.clientWidth * target.header.widthPerc;
target.header.style.height = (target.clientHeight * target.header.height) + 'px';
target.header.style.width = (target.clientWidth * target.header.width) + 'px';
target.header.style.borderBottom = '1px solid black';
target.header.style.position = 'absolute';
target.header.style.top = '0px';
target.header.style.left = ((target.clientWidth - target.header.width) / 2) + 'px';
target.appendChild('target.header');
</script>
}
In my example, the target
is meant to be the current element held by the CSS selector
As you can see, this is a CSS class selector with a block of Javascript inside of it, which of course, does not work. The theory is that this block of Javascript acts as a template for each element captured by the CSS selector (similarly to angular.js, yet compiled at the same time as the CSS). Is there a way that something like this could be done already (without the use o third-party libraries or frameworks)?.
Another use that I would want this for would be something like this:
HTML:
<img class="image1" ></img>
CSS:
.image1{
<script>
target.src = "(URL for image)";
</script>
}
If there is any current way to do any of these things, please let me know!