Background:
I am trying to test a solution to the question here: How to make toggle hidden by default. The code uses jquery to toggle text (with "hidden" being the default).
Problem:
When I add <link rel="stylesheet" href="../../bootstrap-3.3.4-dist/css/bootstrap.min.css"> (a library I'm using for a couple of other webpages) , the jquery query commands no longer work. When I click the link to toggle text, nothing happens.
What I've tried:
I thought the problem had something to do with the way jquery is loading on the page. So I tried changing the position of the script tag to after the body (as well as in the head) to see if that would make a difference.
I looked at the question here (Jquery Datatables and Bootstrap Toggle Doesn't work Together), but the answer says to use jquery's on() method to bind events (at least I think that's what is being said). However, I don't think binding events is the problem because, in my case, the jquery doesn't work when the styling libraries are added (those should not affect the functionality of jquery right?).
Question:
Could someone please explain why/ how the CSS library stops jquery from working? Can you point me in the direction of some useful documentation? Also, is there a workaround for this issue? If anything, I would have thought the two different versions of the jQuery libraries would have caused the issue. I'm pretty new to jQuery, so any advice is appreciated.
Code:
<!DOCTYPE html>
<html>
<head>
<style>
.hidden {
display:none;
}
</style>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="../../bootstrap-3.3.4-dist/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="../../bootstrap-3.3.4-dist/css/bootstrap.min.css">
<script src="../../bootstrap-3.3.4-dist/js/bootstrap.min.js"></script>
<script src="../../fileLoader.js"></script>
<script>
function toggler(divId) {
$("#" + divId).toggle();
}
</script>
</head>
<body>
<a href="#" onclick="toggler('myContent');">this is a test</a>
<div id="myContent" class='hidden'>
<div>this is a test #1 </div>
</div>
<br />
<a href="#" onclick="javascript:toggler('myContentt');">
<span>this is a text</span>
</a>
<div id="myContentt" class='hidden'>
this is a test #2
</div>
</body>
</html>