I’m very new to jQuery, and I would like some insight on how to make this very simple jQuery function something that can actually execute. I am trying to apply jQuery to WordPress, hence is why my code begins with “jQuery” rather than the standard “$”. The task I wish to accomplish with this little test function is simply append the word “test” to the end of a block of test, but as it stands my function is returning a ” Uncaught ReferenceError: test is not defined” error. The code I’m trying to execute is fully shown below:

jQuery(function () {
    function test() {
        $( ".about-us" ).append( "<p>Test</p>" );
    }
})

And this is how I’m calling said script on my page (at the very bottom):

<script type="text/javascript" src="/mysite/wp-
content/themes/RainForest/slider.js"></script>
<script type="text/javascript">
<!--
test();
//--></script>

Any insights that could help enlighten me on how to solve this and future conundrums would be greatly appreciated.

Read more here: Why is my Simple jQuery Function not Defined?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: