Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function container(selector, test, stylesheet) {
- var tag = document.querySelectorAll(selector)
- var style = ''
- var count = 0
- for (var i=0; i<tag.length; i++) {
- var func = new Function(`return ${test}`)
- var attr = (selector+test).replace(/\W+/g, '')
- if (func.call(tag[i])) {
- tag[i].setAttribute(`data-${attr}`, count)
- var css = stylesheet.replace(/\$this/g, `[data-${attr}="${count}"]`)
- style += css
- count++
- } else {
- tag[i].setAttribute(`data-${attr}`, '')
- }
- }
- return style
- }
Add Comment
Please, Sign In to add comment