Hi everyone, I’m working on learning more about object oriented programming by taking an existing Todoapp and converting the code into object oriented style programming. I was wondering if document.querySelector can be a value of an object property in a constructor function? On lines 2-5 of my Code Pen is the reason the object property with the querySelector values undefined because of the binding of the this keyword? Do I have to store the query Selectors in variables instead? Here is my Code Pen link https://codepen.io/paolo3098/pen/xxdPWmJ
Nope, the problem is that none of the classes in your HTML match up with your query strings.
For example, you have
<input type="text" class="todoInput" /> in the HTML but you’re querying for
.toDoInput, they don’t match.
If you want something to happen when the button is clicked, you’ll need to bind a click event listener to it.
You’ve certainly defined a method that changes the body’s background color to blue. But that method is never called. You need to either explicitly call it in your script a la
a.addColor(), or you need to bind a click listener to the button with something like
() => a.addColor().
Ok that worked for me, so I just forgot to call the method like you would normally do with a regular function. Thanks for your prompt responses.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.