Skip to content

Instantly share code, notes, and snippets.

@srifqi
Forked from 140bytes/LICENSE.txt
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srifqi/91a765cb5a0dcb925454 to your computer and use it in GitHub Desktop.
Save srifqi/91a765cb5a0dcb925454 to your computer and use it in GitHub Desktop.
Apply CSS to a list of element

140byt.es

A tweet-sized, fork-to-play, community-curated collection of JavaScript.

Apply CSS to a list of element

//the function
var css=function(){for(var b=[].slice.call(arguments),a=b.length-2,c=b[a+1];a>-1;a--)for(var d in c)b[a].style[d]=c[d];}
//apply to body and head that "backgroundColor" is "black" and the "color" is "white"
css(document.head, document.body, {
    "backgroundColor":"black",
    "color":"white"
});
function(){
for( //for loop
var b=[].slice.call(arguments), //list of element
a=b.length-2, //loop from last element
c=b[a+1]; //the style
a>-1; //until first element
a-- //count the index downward
)
for(var d in c) //for every parameter in style
b[a].style[d]=c[d]; //apply style to element
}
function(){for(var b=[].slice.call(arguments),a=b.length-2,c=b[a+1];a>-1;a--)for(var d in c)b[a].style[d]=c[d];}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 srifqi srifqi.github.io
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "ApplyCSSToElement",
"description": "Apply CSS to a list of element.",
"keywords": [
"apply",
"css",
"element",
"list"
]
}
<!DOCTYPE html>
<title>Foo</title>
<div>Expected value: <b>1px solid black</b></div>
<div>Actual value: <b id="ret"></b></div>
<script>
// write a small example that shows off the API for your example
// and tests it in one fell swoop.
var myFunction = function(){for(var b=[].slice.call(arguments),a=b.length-2,c=b[a+1];a>-1;a--)for(var d in c)b[a].style[d]=c[d];}
myFunction(document.body,{"borderBottom","1px solid black"});
document.getElementById( "ret" ).innerHTML = document.body.style.borderBottom;
</script>
@atk
Copy link

atk commented Jan 27, 2015

How about:

function(){for(var b=[].slice.call(arguments),a=b.length-1,c=b[a];a--;)for(var d in c)b[a].style[d]=c[d]}

?

Update: just forgot a semicolon - fixed.

@srifqi
Copy link
Author

srifqi commented Jan 28, 2015

Do you mean this:

function(){for(var b=[].slice.call(arguments),a=b.length-2,c=b[a+1];a>-1;a--)for(var d in c)b[a].style[d]=c[d];}

?
Your code is wrong, but nice idea! Thanks!
Never thought about that!
So, updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment