I am using cakephp 2.9.9, I want to use a simple jquery function and included in default.ctp, but it is not working as expected. Details are as follows:
1.I have downloaded the JQuery Library jquery-3.2.1.js, my javascript file name is script.js, I kept these two files in /app/webroot/js folder.
2.In my default.ctp file I have added the following lines -
echo $this->Html->script('jquery-3.2.1');
echo $this->Html->script('script');
echo $scripts_for_layout;
3.I want to change style of my navigation menu based on the current active link. My script.js file is as follows -
(function(){
console.log(1); //this can be seen on console
$("#nav a").on("click", function(e){
console.log(2); // this cannot be seen on console
$("#nav a").removeClass('active');
$(e.currentTarget).addClass('active');
});
})();
4.When I open my page, the page calls the script file (as 1 is executed on console) but it is not calling the .on() function of jquery. Any idea why this is happening?