I'm trying to create a simple buzzfeed quiz with HTML and JavaScript as a practice project. All my options are divs of subdivs in HTML. The four options are a div, the top row of two options is a subdiv, and then each option is a subdiv under that. So my HTML looks like:

<div id="q1">
  <p class="question">What's your favorite kind of bread?</p>
  <!-- First set of options -->
  <div class="optionsSet">
    <!-- Sourdough -->
    <div class="option" id="sourdough">
      <img class="optionPic" src="/pictures/b-sour.jpg" alt="Sourdough" id="sourpic">
      <p class="caption">Sourdough</p>

I can't get my JS event listener to grab onto anything. Instead it executes immediately upon loading the page no matter which event I'm trying to hone in on. Here's the latest that I think should be foolproof but it's not working:

var test = new function test() {
  console.log("test succeeded");

document.getElementById('sourdough').addEventListener("mouseup", test)

Once I get this formatted and able to produce an output predictably and reliably I'll tinker with the actual outputs. For no,w I can't even get to that part!

New contributor
rook218 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Remove the "new" from your code and it should be fine.

Your Answer

rook218 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.