Topic: jQuery only works in browser console

BMarkus pro asked 6 years ago


Hello everyone. When I was trying to add this jQuery code to the main file I didn't get any response.
$(document).ready(function() {
 alert( 'ready!');
});
So I tried to paste that code to my browser console and there it works! I hope you can help me with this problem, cause I have to chance to execute some jQuery. All required .js-files are implemented. Other jQuery functions for example modals working fine. I didnt make any changes to the .js-files. Thank you very much! Regards, Markus

Ollie Vincent pro answered 6 years ago


Hi,

I know you said that all required js files are implemented. The fact that when you paste the js into your browser and it works shows this. If you are pasting this code into a new js file please check the file url is correct.

Also, could you try pasting it at the bottom of your html file (just before the closing </body> tag) - it might be that it can't be picked up in external js files.

If you are still having problems, please could you share a link/share your code and I will try to help more.

Thanks


BMarkus pro commented 6 years ago

Hi Ollie, you're wonderful! I have a mvc-based web project, so I placed the jQuery code at the end of the view. This means, that the implementation of the js-files was behind the jQuery code. Now I wrote the code into the main-view before the /body-tag so everything is correct and works fine! Thank you! Have a nice day!


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags