Error of: Uncaught TypeError: undefined is not a function

1
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css">
    <link href="~/Content/Menu.css" rel="stylesheet" />

    <script src="@Url.Content("~/Scripts/jquery-1.10.2.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery-1.10.2.min.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery-2.1.0.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery-2.1.0.min.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery-migrate-1.2.1.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery-migrate-1.2.1.min.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui.min.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery.maskedinput.min.js")"></script>
    <script src="@Url.Content("~/Scripts/Menu.js")"></script>

    <script src="@Url.Content("~/Scripts/main.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery-color.js")"></script>

    <script src="@Url.Content("~/Scripts/Util.js")"></script>
    <script src="@Url.Content("~/Scripts/Pesquisa/Pesquisa.js")"></script>

Here is the error quoted above:

$("#txtCnpjPesquisa").mask("99.999.999/9999-99");

How do I resolve this.

My jquery function

jQuery(function ($) {
    //$("#date").mask("99/99/9999");
    //$("#phone").mask("(99) 999-9999");
    //$("#cep").mask("99.999-99");
    //$("#cpf").mask("99.999.999-99");
    $("#txtCnpjPesquisa").mask("99.999.999/9999-99");
});

Following the suggestion of Philip and GuilehermeBernal, my cshtml was thus:

<script src="@Url.Content("~/Scripts/jquery-ui.min.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery.maskedinput.min.js")"></script>
    <script src="@Url.Content("~/Scripts/Menu.js")"></script>

    <script src="@Url.Content("~/Scripts/main.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery-color.js")"></script>

    <script src="@Url.Content("~/Scripts/Util.js")"></script>
    <script src="@Url.Content("~/Scripts/Pesquisa/Pesquisa.js")"></script>
    
asked by anonymous 05.05.2014 / 15:56

4 answers

5

To pass jQuery as alias of $ (and thus avoid conflicts ) should do so:

(function( $ ) {
  $(function() {
    // O seu código com dolar aqui      
  });
})(jQuery);

Apart from this detail it seems to me that you are including 5 versions of jQuery in the same document. This is going to (give) problems. Choose one and remove the others. If possible keep the last ...

So your code could be:

(function( $ ) {
  $(function() {
    //$("#date").mask("99/99/9999");
    //$("#phone").mask("(99) 999-9999");
    //$("#cep").mask("99.999-99");
    //$("#cpf").mask("99.999.999-99");
    $("#txtCnpjPesquisa").mask("99.999.999/9999-99");
  });
})(jQuery);

Regarding jQuery versions, 4 seems to me to be:

<script src="@Url.Content("~/Scripts/jquery-1.10.2.js")"></script>
<script src="@Url.Content("~/Scripts/jquery-1.10.2.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery-2.1.0.js")"></script>
<script src="@Url.Content("~/Scripts/jquery-2.1.0.min.js")"></script>

and possibly the last one, below:

<script src="@Url.Content("~/Scripts/jquery.js")"></script>

You should only have one.

    
05.05.2014 / 16:22
1

Try this:

$(document).ready(function(){
     $("#txtCnpjPesquisa").mask("99.999.999/9999-99");
});

Another thing, you're doing includes duplicates, files with ".min.js" are cleaner versions, meaning no spaces and comments, the load of those files is faster when you open a page.

Remove the following lines (includes duplicates):

<script src="@Url.Content("~/Scripts/jquery-1.10.2.js")"></script>
<script src="@Url.Content("~/Scripts/jquery-2.1.0.js")"></script>
<script src="@Url.Content("~/Scripts/jquery-migrate-1.2.1.js")"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.js")"></script>

You're also including two versions of jquery:

<script src="@Url.Content("~/Scripts/jquery-1.10.2.js")"></script>
<script src="@Url.Content("~/Scripts/jquery-1.10.2.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery-2.1.0.js")"></script>
<script src="@Url.Content("~/Scripts/jquery-2.1.0.min.js")"></script>

Delete a version, suggest that you stay with version 1.10 because it is compatible with IE8, delete the lines:

<script src="@Url.Content("~/Scripts/jquery-2.1.0.js")"></script>
<script src="@Url.Content("~/Scripts/jquery-2.1.0.min.js")"></script>
    
05.05.2014 / 16:12
0

I was having a similar problem and resolved with the following code

(function( $ ) {
  $(function() {
    // O seu código com dolar aqui      
  });
})(jQuery);
    
12.08.2017 / 04:14
-2

In my case, this error happened because I was loading the .js file that called .mask before jquery. After correcting the order that the files were loaded the error did not occur any more.

    
04.11.2016 / 00:20