Last active
February 23, 2023 10:38
-
-
Save daanta-real/b9f12d885f62fbd043b7c9fb6aa14d54 to your computer and use it in GitHub Desktop.
Give dynamic rainbow colored borders to ALL the elements being found in query. Quite useful for testing CSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Give dynamic rainbow colored borders to ALL the elements being found in query. Quite useful for testing CSS | |
function rainbow(query, styles) { | |
var colors = ['Red', 'Lime', 'Blue', 'Yellow', 'Cyan', 'Magenta', 'Silver', 'Gray', 'Maroon', 'Olive', 'Green', 'Purple', 'Teal', 'Navy'] | |
document.querySelectorAll(query).forEach(function(el) { | |
var rand = Math.floor(Math.random() * colors.length); | |
var color = colors[rand]; | |
el.style.border = '2px ridge ' + color; | |
if(styles != undefined) { | |
for(var [key, val] of Object.entries(styles)) { | |
el.style[key] = val; | |
} | |
} | |
}); | |
} | |
// Try this | |
rainbow("body *", {background: 'red'}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment