Running own jQuery Code

nicepage43
4 Posts
nicepage43 posted this 21 March 2019
Ask a Question

Hi,

I like to run some small scripts by jQuery inside my nicepage. As I understand I can add them in the Site Settings, Additional Head HTML. I also see jQuery 1.9.1 is loaded before my code. But if I do something like

$(function() {
// Handler for .ready() called.
});

or

jQuery(function() {
// Handler for .ready() called.
});

I get error messages like jQuery is not defined.

I don't like to include a second instance of jQuery. I think it should be possible to use the already installed jQuery. So what do I have to do to use jQuery?

Kind regards
Christoph

Hi, I like to run some small scripts by jQuery inside my nicepage. As I understand I can add them in the Site Settings, Additional Head HTML. I also see jQuery 1.9.1 is loaded before my code. But if I do something like $(function() { // Handler for .ready() called. }); or jQuery(function() { // Handler for .ready() called. }); I get error messages like jQuery is not defined. I don't like to include a second instance of jQuery. I think it should be possible to use the already installed jQuery. So what do I have to do to use jQuery? Kind regards Christoph

Last edited 21 March 2019 by nicepage43

Vote to pay developers attention to this features or issue.
3 Replies
Order By: Standard | Newest
Support Team
Support Team posted this 21 March 2019

Hi Christoph,

Please check the following article:
https://nicepage.com/doc/article/29438/how-to-run-custom-jquery

It happens because the jQuery library is loaded with defer attribute. It specifies that the script is executed when the page has finished parsing. Therefore the custom jQuery code should have the corresponsive wrapper which makes your code run after the page is loaded.

<script>  
  window.onload = function() {
// your code here
}
</script>

or

<script>  
 window.addEventListener('load', function () {
// your code here
}
</script>

Please let us know if you have any further questions.

...................................................
Sincerely,
Olivia
Nicepage Support Team

Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1
Follow us on Facebook: http://facebook.com/nicepageapp

Hi Christoph, Please check the following article: https://nicepage.com/doc/article/29438/how-to-run-custom-jquery It happens because the jQuery library is loaded with *defer* attribute. It specifies that the script is executed when the page has finished parsing. Therefore the custom jQuery code should have the corresponsive wrapper which makes your code run after the page is loaded. <script> window.onload = function() { // your code here } </script> or <script> window.addEventListener('load', function () { // your code here } </script> Please let us know if you have any further questions. ................................................... Sincerely, Olivia Nicepage Support Team Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1 Follow us on Facebook: http://facebook.com/nicepageapp
nicepage43
4 Posts
nicepage43 posted this 21 March 2019

Hi Olivia

Thanks a lot. This works perfect.

Kind regards
Christoph

Hi Olivia Thanks a lot. This works perfect. Kind regards Christoph
Support Team
Support Team posted this 21 March 2019

Hi Christoph,

You are welcome. Let us know if you need further assistance.
...................................................
Sincerely,
Elena
Nicepage Support Team

Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1
Follow us on Facebook: http://facebook.com/nicepageapp

Hi Christoph, You are welcome. Let us know if you need further assistance. ................................................... Sincerely, Elena Nicepage Support Team Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1 Follow us on Facebook: http://facebook.com/nicepageapp
You must log in or register to leave comments