Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

script order for jquery with bootstrap

I'm new to jquery and bootstrap, and I can't get them to play nicely with each other. I have a page with both bootstrap dropdowns and jquery sliders. However, I can't get both of them to work at the same time.

Bootstrap dropdowns work with this file, and sliders break

<html lang="en">
<head>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" media="all" />
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
    <link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <script src="/js/slider_input.js"></script>
</head>

<body>
....
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <script src="/bootstrap/js/bootstrap.min.js"></script> 

</body
</html

By removing the second to last line like so:

Sliders work, and bootstrap dropdowns break

<html lang="en">
<head>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" media="all" />
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
    <link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <script src="/js/slider_input.js"></script>
</head>

<body>
....

    <script src="/bootstrap/js/bootstrap.min.js"></script> 

</body
</html
like image 687
bcoop713 Avatar asked Jun 04 '13 19:06

bcoop713


People also ask

Can you use jQuery and Bootstrap together?

It's possible! Bootstrap 5 is designed to be used without jQuery, but it's still possible to use our components with jQuery. If Bootstrap detects jQuery in the window object it'll add all of our components in jQuery's plugin system; this means you'll be able to do $('[data-bs-toggle="tooltip"]').

Should Bootstrap Bootstrap min js file be loaded before or after jQuery?

Note that the functionalities of some JavaScript components like tabs and dropdowns depend on popper. js and jQuery. Hence, before loading the Bootstrap JavaScript file, include the jQuery and Popper CDN before loading the bootstrap. min.

What should I learn first Bootstrap or jQuery?

Since Bootstrap uses jQuery, the answer should be apparent: jQuery first.

Can you use JavaScript and Bootstrap together?

You can absolutely use custom JavaScript on top of Bootstrap's default scripts. You'll want to keep your custom script(s) in a separate file to Bootstrap's JavaScript, remembering that external files are loaded from top-to-bottom, and that you'll need to load jQuery before loading Bootstrap's JavaScript.


2 Answers

oh yeah now i see sorry. You have to load your actual jquery first, else UI won't work either. So this should be the head

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> 
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script> 
<script src="/bootstrap/js/bootstrap.min.js"></script> 
<script src="/js/slider_input.js"></script>

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" media="all" />
<link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">

Also in html5 you need to leave off the 'type="text/javascript"', like the bootstrap one, also be consisten, so if you have it on the other, also add it to the bootstrap, it has to do with loading rules.

like image 107
Tobias Hagenbeek Avatar answered Oct 08 '22 16:10

Tobias Hagenbeek


"jQuery must come first, then Popper.js, and then our [bootstrap] JavaScript plugins." Bootstrap 4.x javascript script order: getbootstrap.com

like image 30
Tyson Gibby Avatar answered Oct 08 '22 17:10

Tyson Gibby