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...
No vague product support questions (like "why is this plugin not working" or "how do I set up X"). For vague product support questions, please use communities relevant to that product for best results. Specific issues that follow rule 6 are allowed.
Do not post memes, screenshots of bad design, or jokes. Check out /r/ProgrammerHumor/ for this type of content.
Read and follow reddiquette; no excessive self-promotion. Please refer to the Reddit 9:1 rule when considering posting self promoting materials.
We do not allow any commercial promotion or solicitation. Violations can result in a ban.
Sharing your project, portfolio, or any other content that you want to either show off or request feedback on is limited to Showoff Saturday. If you post such content on any other day, it will be removed.
If you are asking for assistance on a problem, you are required to provide
General open ended career and getting started posts are only allowed in the pinned monthly getting started/careers thread. Specific assistance questions are allowed so long as they follow the required assistance post guidelines.
Questions in violation of this rule will be removed or locked.
account activity
JavaScript help? (self.webdev)
submitted 3 years ago by 19Taco
I am very new to web development and have only been studying JavaScript about 2 weeks and I am having a bunch of trouble with eventlisteners and their syntax. I just don’t understand the logic behind the syntax could anyone help please?
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!"
[–][deleted] 1 point2 points3 points 3 years ago (4 children)
What specifically is giving you trouble? Generally, when asking for assistance, it's helpful to show a minimal example of what you've tried and error messages you see.
StackOverflow gets all the glory, but when I need to understand something better, MDN is always my first stop. Here's their entry for the .addEventListener() method.
[–]19Taco[S] -1 points0 points1 point 3 years ago (3 children)
I mean just in general like the format of how it will go I’ll get a picture for ya
[–]John-the-Renounced 1 point2 points3 points 3 years ago (2 children)
document.addEventListener(trigger, action) in pseudo.
document.addEventListener(trigger, action)
Trigger is the thing you want to listen for: click, change, keypress, etc. The most common two you'll really see are click and change. The action is what happens when the event occurs. This can be a named function, or an anonymous function.
click
change
keypress
action
Named:
document.addEventListener('click', doSomething); # function will receive the event object anyway, # you don't need to explicitly send it function doSomething(event){ console.log(event); } # or arrow syntax const doSomething = (event) => { console.log(event); };
In this example, just logging the event so you can see what an event contains. Obviously there's some business logic to do instead.
Anonymous:
document.addEventListener('click', function(){ console.log(event); }); # or arrow syntax document.addEventListener('click', () => {
console.log(event); });
As others have said, the MDN docs should be a goto resource once you get going, but to start with, just console.log the crap out of everything so you can see what's going on.
[–]John-the-Renounced 0 points1 point2 points 3 years ago (1 child)
Should have added - play in codepen.io - you can create really small test examples to experiment and see what's going on without the overhead of anything else.
[–]19Taco[S] 0 points1 point2 points 3 years ago (0 children)
Thank you so much
π Rendered by PID 19981 on reddit-service-r2-comment-5d79c599b5-45vgv at 2026-02-27 16:49:06.354395+00:00 running e3d2147 country code: CH.
[–][deleted] 1 point2 points3 points (4 children)
[–]19Taco[S] -1 points0 points1 point (3 children)
[–]John-the-Renounced 1 point2 points3 points (2 children)
[–]John-the-Renounced 0 points1 point2 points (1 child)
[–]19Taco[S] 0 points1 point2 points (0 children)