admin管理员组

文章数量:1315960

I am having trouble initializing some Materialize-css javascript functions; the one in particular is material_select().

I am trying to initialize the function as stated in the Materialize docs:

$(document).ready(function() { $('select').material_select(); });

However, I get the following error: $(...).material_select is not a function

material_select() as well as any other Materialize function initializes if I manually write it into the browser console, but not if it's in the code; I am importing jQuery before materialize.js as well.

Help is much appreciated, thank you.

I am having trouble initializing some Materialize-css javascript functions; the one in particular is material_select().

I am trying to initialize the function as stated in the Materialize docs:

$(document).ready(function() { $('select').material_select(); });

However, I get the following error: $(...).material_select is not a function

material_select() as well as any other Materialize function initializes if I manually write it into the browser console, but not if it's in the code; I am importing jQuery before materialize.js as well.

Help is much appreciated, thank you.

Share Improve this question asked Dec 7, 2016 at 18:38 Lane FujikadoLane Fujikado 1351 gold badge3 silver badges11 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

You are most likely loading materialize.js before jQuery or your jQuery version is too high and not working with materialize. You need to add some code here!

Double check that jQuery and Materialize are initialized before the document ready function is called.

For example:

<script type="text/javascript" src="https://code.jquery./jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
<script>
$(document).ready(function() {
    $('select').material_select();
});
</script>

And of course make sure that the appropriate CSS files are imported in <head>

It is impossible to give the exact solution without referring your code. Problem may be happened in the materialize.js file. It would be better if you test following fully working code and find your issue.

Working code

Click Run Code Snippet in the given link for live demo or copy full code and test in your machine.

本文标签: javascriptInitializing Materialize functionsStack Overflow