Message from JavaScript discussions

September 2020

— JavaScript engines check🦾👨‍🚀🦿

— 

Hey guys I am having an issue in javascript

I’m trying to do

document.querySelector(“.product-card-“+targetId).innerHTML

I am expecting targetId (which is 1) to type coerce into a string so that I can fetch that element from the DOM

But instead console says cannot read property ‘innerHTML’ of null

Also
1. Script tags are already in the end of body tag. So DOM is loaded.
2. I am using IIFEs

— If I complete the string inside querySelector then the error vanishes

— Put the debugger before the call and check scope for correct parameters🤔

— Console.log(targetId)

— What is it set to?

— 1ct on undefined

— Scope is alright

— Just a number

— Well the class doesn't exist then

— It does

— It was probably a problem with reading the dom elements