Using 2 libraries at same page: jQuery UI and Twitter Bootstrap:
To fix the collision between Bootstrap and jQuery UI functions, rename one of them:
<script type="text/javascript" src="bootstrap.min.js"></script>
<script type="text/javascript">
$.fn.bsbutton = $.fn.button;
</script>
<script type="text/javascript" src="jquery-ui.min.js"></script>
And then you can call each function at will:
<script type="text/javascript">
$(".button-one").button() // jQueryUI button
$(".button-two").bsbutton() // Bootstrap button
</script>
You can use this technique for any function you need.
Remember the order include A -> rename A -> include B
.
All other answers fixing conflict between jQuery UI button and bootstrap button but you can't use bootstrap data-api for renamed button()
function. Only manually using new-named bootstrapBtn()
function.
I find a solution:
(\$[.\w]+\.)button
to \1btn
in bootstrap.js
file.Or use this sed
script:
#!/bin/bash
# Change bootstrap3 $.fn.button() function to $.fn.btn() for no conflict with jQuery UI
sed "s/\(\$[[:alnum:]._]\+\.\)button/\1btn/g" bootstrap/js/bootstrap.js > bootstrap/js/bootstrap.btn.js
sed "s/\(fn\.\)button/\1btn/g" bootstrap/js/bootstrap.min.js | sed "s/button\((\)/btn\1/g" > bootstrap/js/bootstrap.btn.min.js
After that you can use bootstrap data-api for button binding and also manually use btn()
function in place of button()
for Bootstrap while still use jQuery UI button()
function.
I suggest to do custom jQueryUI, or Bootstrap build - both offer this possibility on websites.
I use custom build of jQueryUI with core, effects, interactions, but without widgets, which often causes conflicts.
The current version of bootstrap (v2.2.2) now has a noConflict option. Just insert this some place after your bootstrap and jquery script tags but before any usage of the button()
function.
<script type='text/javascript'>
$.fn.bootstrapBtn = $.fn.button.noConflict();
</script>
Alternatively, you can use $(document).ready(handler)
, but you still have to make sure substitution occurs before button()
is called.
Once that line of code is executed, button()
will be JqueryUI's button, and bootstrapBtn()
will be Bootstrap's version.
If you are only using the dropdown plugin of Twitter Bootstrap, you don't need the .button()
plugin.
Go to the customize bootstrap page and unselect all jQuery plugins, then choose only the dropdown one. You could also unselect some of the CSS if you want.
.button
to something like .bsButton
in the bootstrap-button.js file (or find this section in a non-minified version) - not tested.