Currently, I am facing an issue with a module that includes a switch statement generating content and various on
events waiting based on the content inserted into the DOM and the trigger activated.
The problem arises when using on
event handlers with dom.byId('foo')
:
on(dom.byId('foo'), touch.press, function(e){
This results in an error:
Uncaught TypeError: cannot read property 'on' of null
.
I suspect this occurs because the node foo
may not exist if a different switch condition is met. To workaround this, I have started using a CSS class instead:
on(query('.foo'), touch.press, function(e){
However, this poses a similar risk as using the id
!
As someone new to Dojo, learning its ins and outs has been quite a journey. I would like to understand why this error is happening and whether it indicates a significant problem on my end.