I always get error "M is not defined" el is not defined
codepen sample
if you open console, you will see the error
I first load jquery.min.js then load materialize.min.js .css
then load my script.js below.
M is not recognized, which it should
why?
// init materialize tab
var instance = M.Tabs.init(el, options);
// Or with jQuery
$(document).ready(function(){
$('.tabs').tabs();
});
This is html
<div class="row">
<div class="col s12">
<ul class="tabs">
<li class="tab col s3"><a href="#test1">Test 1</a></li>
<li class="tab col s3"><a class="active" href="#test2">Test 2</a></li>
<li class="tab col s3 disabled"><a href="#test3">Disabled Tab</a></li>
<li class="tab col s3"><a href="#test4">Test 4</a></li>
</ul>
</div>
<div id="test1" class="col s12">Test 1</div>
<div id="test2" class="col s12">Test 2</div>
<div id="test3" class="col s12">Test 3</div>
<div id="test4" class="col s12">Test 4</div>
</div>
Materialize CSS is a design language that combines the classic principles of successful design along with innovation and technology. It is created and designed by Google. Google's goal is to develop a system of design that allows for a unified user experience across all its products on any platform.
With outstanding pull requests with mostly no feedback from project members it's safe to say this project is now abandoned.
Materializecss is no longer supported · Issue #6615 · Dogfalo/materialize · GitHub.
I found the problem, it is version.
Make sure you use version => 1.0.0.
https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js
If you use version <1.0.0 very likely you have error as 'M is not defined'
Make sure you load jquery before materialize css !
Also you must first define elem and options to init tab
// init materialize tab
var elem = $('.tabs')
var options = {}
var instance = M.Tabs.init(elem, options);
//or Without Jquery
//var elem = document.querySelector('.tabs');
var options = {}
var instance = M.Tabs.init(elem, options);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With