I am trying to console log the value of the input with the ID ‘task-1’ to see if I am targeting it properly. I input a value into the input field and nothing is happening in the console.
You need an event/function to run to get the input value after something is typed. Right now you are just getting the initial value from when the code first runs (which is an empty string).
I’ve done a bit of googling to try to find out what that event/function might be, but I haven’t found what I need. I thought maybe assign whatever is typed in to a variable and do something with that, but how do I target what is typed in - is there even a specific name for values that are typed into input fields? Maybe I’m not using the right language in my search.
On a separate note, I found a video that shows me that is I type ‘task1.value’ directly into the console, I can access the valued that is typed in. Just curious why my console log doesn’t work then, assuming I have typed something into the field of course (as I did when I tested the command directly in the console)?
You should do more of the new JS curriculum. It will teach you what you need to know.
You more or less have 3 options.
Use a button and get the input value inside the button click event handler.
Add an event listener to the input element and use the "input" or "change" event. Get the input value inside that event handler (input is all inputs, change is on enter).
Use a form and get the values on a form submission. Using the FormData API is also an option. But this option is a bit overkill for a single input.
I can’t really answer that but the console has a context dropdown and you need to be inside the correct context. You will usually be inside the correct context if you open the dev tools using the right-click Inspect option on the page.
Also, something very handy you should know about is the $0 command. If you select an element in the Inspector, in the console $0 will be that element.
I am probably trying to do some things that I haven’t read about/studied yet as I am reading a book about the fundamentals when I get time and googling the rest.
Would you recommend a particular source for the new JS curriculum?