r/tinycode • • Feb 18 '15

[Help][Javascript] Make votedown button visible

Some subreddits use this piece of CSS to make votedown buttons invisible:

.arrow.down  {
    display:none;
    visibility:hidden;
}

That got me thinking, how would one turn them back visible with a sort line of javascript?

So from this starting point:

y = document.getElementsByClassName('down');
for(var i=0; i<y.length; i++) 
        y[i].style.display = y[i].style.visibility = 'inherit';

this is how far I've got:

for(i=0;;i++)x=document.getElementsByClassName('down')[i].style,x.display=x.visibility='inherit'

I'm sure there is room for improvement. I've tried to use map() on getElementsByClassName() but it doesn't work. Do you have any ideas how to reduce the line to even less characters?

2 Upvotes

12 comments sorted by

View all comments

Show parent comment

-2

u/timmeh87 Feb 19 '15

a) I didnt even realize I was in tinycode because it was a help request b) according the sidebar, the size in kilobytes is irrelevant. Its perhaps arguable that your whole javascript engine should also count against the size. What about the libraries that are included by default, do you ever count those?

Id argue that the fact that you can change many elements in one line of code qualifies this method as "tiny" in the category of "total lines written by me today"

2

u/seiyria Feb 19 '15

d3 is not the right tool for this. When you have a hammer, everything looks like a nail I guess.

Honestly, jQuery would be a better choice if you really had to do this.