Why does jQuery mask say it's not a function?

Jack picture Jack · Feb 14, 2015 · Viewed 66k times · Source

When trying to use the jQuery mask() function, I get the following error in the console:

TypeError: $(...).mask is not a function

This is a sample of my code where this is happening:

<html>
<body>
<input type='text' id='phone' />
</body>

<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>

<script>
//alert($);
$(document).ready(function(){

        $("#phone").mask("(99) 9999-9999");
});
</script>

</html>

How do I fix this?

Answer

Gnucki picture Gnucki · Feb 14, 2015

Jquery mask is a plugin. You can directly add this line in your HTML if you want to use a CDN version:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.10/jquery.mask.js"></script>

Another way is to use a package manager like npm or bower. To accomplish that, follow the instructions in the README.md file of the project.