JS Event Does not Trigger From File

APD Toronto
APD Toronto used Ask the Experts™
on
Hi Experts,

If you go to http://aces-project.com/2017/_NEW.php and click on the hamburger menu right of the email, you will see that nothing happens. Whereas you wll see that in js/header.js, line 78 I have a trigger.

Even more stranger when I copy the following into chrome console and click on the hamburger, it does triiger the alert.
$('#divMobileBars').on('click', function(){
    alert('xyz');
});

Open in new window


Any help will be appreciated.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Owner (Aidellio)
Most Valuable Expert 2015
Commented:
it's because the dom hasn't completely loaded yet.. as you're including your header.js in the <head> section.

wrap your javascript in the jQuery init function

e.g.

$(function() {
$('#divMobileBars').on('click', function(){
    alert('xyz');
});
});

or alternatively put the header.js at the end of the file, just before the </body> tag.  I personally prefer the former (the init function)
APD TorontoSoftware Developer

Author

Commented:
Thank you so much, I forgot about it!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial