0

I've included jQuery in my page in head tag:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

But Chrome says that code which uses jQuery is incorrect and I see the error "$ is not defined":

$(".product").on('click', function() {

    var cv = $(this).attr("id");

    $.get("cvs/cv"+cv+".html", function(text){ 
        $(".about").html(text);
    });

});

But this code works in Mozilla Firefox. What's wrong?

boguchar
  • 89
  • 10

2 Answers2

0

Always try to include your external scripts before the end of the body tag NOT in the head tag. because the document needs to be loaded the read the scripts

example:

<body>
 ...
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
    $(".product").on('click', function() {

        var cv = $(this).attr("id");

        $.get("cvs/cv"+cv+".html", function(text){ 
            $(".about").html(text);
        });

    });
</script>
</body> 

Also the below link helps you and has more descriptions

https://www.w3schools.com/js/js_whereto.asp

Saeed Jamali
  • 1,195
  • 2
  • 7
  • 19
0

First, please check there is another jQuery library included. And please try this code.

jQuery(document).ready(function($){
    $(".product").on('click', function(){
        //Your code
    });
});