Jump to content

Cannot call Dom object


dbawel
 Share

Recommended Posts

Hello,

I've tried every location and jquery syntax for hours, and I still get an error: Uncaught TypeError: Cannot read property 'addEventListener' of null at main2.js:47. It's simply not finding the ID of the variable I've set. Any help is appriciated. It's 3am, so I'm sure I'll feel stupid in the morning.

http://qedsoft.com/DEMOS2017/mobile_app/index2.html

Thanks,

DB

Link to comment
Share on other sites

Loading the script in the head element will call the javascript before the DOM war generated. hence - the dom elements are null.

if you use jquery, you can wrap it in a DOM-Ready function:

$(function() {

// code goes here

});

but you can simply add the javascript at the bottom of the body tag, and it will be executed after the dom was loaded (if you dont create the DOM dynamically)

Link to comment
Share on other sites

@RaananW

Thanks so much for your help. For now I have my JS in my HTML file - not ideal, but keeps me working.

I tried every which way, but no luck no matter what I try.:

22 minutes ago, RaananW said:

if you use jquery, you can wrap it in a DOM-Ready function:

Any thoughts.

Thanks,

DB

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...