Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
| /* | |
| # Prev Selector Mixin for reproCSS | |
| ## version 0.0.10 | |
| Apply CSS styles to the directly preceding sibling of HTML elements matching a CSS selector. | |
| ### Syntax | |
| prev(selector, rule) | |
| - `selector` is a CSS selector | |
| - `rule` is one or more CSS declarations separated by semicolons | |
| ### Example | |
| prev('li:nth-of-type(2)', 'background: lime') | |
| - https://github.com/tomhodgins/reprocss | |
| Author: Tommy Hodgins | |
| License: MIT | |
| */ | |
| function prev(selector, rule) { | |
| var tag = document.querySelectorAll(selector) | |
| var style = '' | |
| var count = 0 | |
| for (var i = 0; i < tag.length; i++) { | |
| var attr = selector.replace(/\W+/g, '') | |
| tag[i].previousElementSibling.setAttribute('data-prev-' + attr, count) | |
| style += '\n/* ' + selector + ':prev */\n' | |
| + '[data-prev-' + attr + '="' + count + '"] {\n' | |
| + ' ' + rule + '\n' | |
| + '}\n' | |
| count++ | |
| } | |
| return style | |
| } |