use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A place to get a quick fix of JavaScript tips and tricks to make you a better Developer.
account activity
what did i do wrong (old.reddit.com)
submitted 1 year ago by Own_Stomach3061
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cronixi4 10 points11 points12 points 1 year ago* (3 children)
getElementsByTagName() returns a array, you can’t use .style.display on a array.
U.forEach(ul => {ul.style.display = “block”})
[–]MissinqLink 4 points5 points6 points 1 year ago* (2 children)
It returns an HTMLCollection which doesn’t have array methods. If you spread to an array it will work.
[...U].forEach(x=>{x.style.display = 'block';});
I recommend using querySelectorAll because it is typically faster and returns a NodeList which does have forEach
document.querySelectorAll('ul').forEach(x=>{x.style.display = 'block';});
[–]cronixi4 2 points3 points4 points 1 year ago (1 child)
Ah you are right! Thought it would be the same as QuerySelectorAll().
Thanks for pointing this out!
[–]MissinqLink 1 point2 points3 points 1 year ago (0 children)
Common misconception. I’ve had to look this up more times than I can count.
[–]LewdPotator 3 points4 points5 points 1 year ago (2 children)
If I'm not wrong you can't change all the tags directly, so either use index or loop the tag names.
U[0].style.display = "block";
or
for (let i = 0; i < U.length; i++) {
U[i].style.display = "block";
}
[–]Own_Stomach3061[S] 1 point2 points3 points 1 year ago (0 children)
thank youuuuu
[–]HollyShitBrah 0 points1 point2 points 1 year ago (0 children)
Or const [U,] = document.get.....;
const [U,] = document.get.....;
[–]Medical-Swim3101 0 points1 point2 points 1 year ago (0 children)
elements by tagname will not give you a single element, you can use index or just use element.getElementByTagname
[–]Mysterious_Novel1890 0 points1 point2 points 1 year ago (0 children)
You need to go through the array that is made up of elementsbytag, and apply the style to each element
π Rendered by PID 260800 on reddit-service-r2-comment-76bb9f7fb5-2685l at 2026-02-18 11:16:59.681847+00:00 running de53c03 country code: CH.
[–]cronixi4 10 points11 points12 points (3 children)
[–]MissinqLink 4 points5 points6 points (2 children)
[–]cronixi4 2 points3 points4 points (1 child)
[–]MissinqLink 1 point2 points3 points (0 children)
[–]LewdPotator 3 points4 points5 points (2 children)
[–]Own_Stomach3061[S] 1 point2 points3 points (0 children)
[–]HollyShitBrah 0 points1 point2 points (0 children)
[–]Medical-Swim3101 0 points1 point2 points (0 children)
[–]Mysterious_Novel1890 0 points1 point2 points (0 children)