Library JS is not defined

0

I have a problem with the libraries, I have a landing page that has its js and css and I have another template for users who have their own css and js except for one that they share between the two and the problem is that in landing it has the login and I do not use datatables then it pulls me error of datatables is not defined or vue is not defined and it does not finish loading the page if I do not import the js, something that if I use in the user template. Is there any way to fix this? I tried to do the next thing I saw on the internet but did not walk:

if (typeof DataTable !== 'undefined') {
   $(".datatables").DataTable();      
}
    
asked by Juan Pablo B 30.06.2017 в 04:47
source

1 answer

1

Keep in mind that DataTable is a plugin assigned to JQuery so you just have to do it this way:

Knowing in advance that DataTable is a JQuery method:

if (typeof $().DataTable == 'function') {
  alert("soy una funcion de JQuery");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>

Simply to know if it does not exist as a variable or function within JQuery:

if (typeof $().DataTable == 'undefined') {
  alert("simplemente no existo");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Adapt the above to your problem promptly, I hope you find it useful.

    
answered by 30.06.2017 / 05:32
source