Referenceerror: $ is not defined JQUERY

Asked

Viewed 774 times

-2

I’m trying to create a rating, but this error persists in my code...

js, I’m using jquery

    $(function(){
    $('.star').on('mouseover', function(){
        var indice = $('.star').index(this);
        $('.star').removeClass('.full');
        for(var i = 0; i<= indice; i++){
            $('.star:eq('+i+')').addClass('full');
        }
    }); 

});

html, jquery inclusion and my . js file

<script src="../js/avaliacao.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>

2 answers

3

Just change the file call order:

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script src="../js/avaliacao.js"></script>

this should solve, if not solve, try importing another jquery file.

2

To become really one PROFESSIONAL in the development area, you need to understand how a particular technology works. In your case you need to understand how the structure works DOM of HTML!

What is a GIFT?

The Document Object Template(DOM) is a programming interface for documents HTML, XML and SVG . It provides a structured representation of the document as a tree. The DOM defines methods that allow access to the tree, so that they can change the structure, style and content of the document. The DOM provides a representation of the document as a structured group of nodes and objects, possessing various properties and methods. Nodes may also have event handlers inherent to them, and once an event is triggered, event handlers are executed. Essentially, it connects web pages to scripts or programming languages. Although the DOM is frequently accessed using JavaScript, is not a part of language JavaScript. It can also be accessed by other languages.

Graphic Example: inserir a descrição da imagem aqui

Knowing this, briefly in which the browser will "read" the structure HTML row by row (top to bottom). Adding the answer from @Theo your error is in the following:

<script src="../js/avaliacao.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>

Note that you entered your file .js first and afterward the jquery, then the browser will "read" and "load" the file first .js, this will result in the error which you are struggling with. To get around this is quite simple, just change the order of <script> for:

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script src="../js/avaliacao.js"></script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.