This is driving me insane.
I have this:
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading" id="panel-head">
<a data-toggle="collapse" data-target="#collapseDiv" class="white-link" id="toggle" >Records Added
<span class="indicator glyphicon glyphicon-chevron-down pull-left pad-right" id ="glyphicon"></span>
</a>
</div>
<div id="collapseDiv" class="panel-collapse collapse">
<div class="panel-body">
And I am trying to fire the collapse with this (in various ways):
$('#collapseDiv').collapse("toggle")
All I get is:
Uncaught TypeError: $(...).collapse is not a function(…)
Any ideas?
```
```
Make sure Jquery is included above Bootstrap, it works fine
$('#collapseDiv').collapse("toggle");
.white-link{color:#fff;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading" id="panel-head">
<a data-toggle="collapse" data-target="#collapseDiv" class="white-link" id="toggle">Records Added
<span class="indicator glyphicon glyphicon-chevron-down pull-left pad-right" id ="glyphicon"></span>
</a>
</div>
<div id="collapseDiv" class="panel-collapse collapse">
<div class="panel-body">
I was having the same problem.... So in JQuery I did something like this:
$('#collapseDiv').removeClass('show');
As mentioned in official doc...
so that is why I removed 'show' class and it worked for me... only drawback is that it hides immediately (without any animation)
I had a similar problem with Lightbox (by Lokesh Dhakar) if I used:
<script src="js/lightbox-plus-jquery.min.js"></script>
but worked with:
<script src="js/lightbox.min.js"></script>
It took me an hour to figure it out.
Here is the simple solution. I will explain with three different method
1. Replace
import * as $ from 'jquery';
with
declare var $ : any;
If it did't solve your problem than
2. make sure you import jquery and bootstrap in index.html as below, jQuery shoud be first
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
If it did't work
3. than install jquery,jquery ui,jquery action and bootstrap
npm install jquery --save
npm install @types/jquery --save
npm install bootstrap --save
Now import in your ts or js file
import * as $ from 'jquery';
Update angular.json file
"styles": [
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss",
"./node_modules/font-awesome/css/font-awesome.css",
"./node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
"./node_modules/jquery/dist/jquery.min.js",
"./node_modules/bootstrap/dist/js/bootstrap.min.js"
]
That all it should work by now,Thanks
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