I've looked at more than a dozen questions about using onclick
, click
, bind("click", ...)
, on("click", ...)
, etc. and have yet to find the issue that I'm having.
Basically it's an expandable div that hides some content when not expanded. I'm using the Twitter Bootstrap collapse
class with a data-toggle button to expand/collapse the content itself, but I also need to modify the CSS of the container div to increase the height so that visually, the box the content is in will stretch to contain it.
Here's my script code:
$(document).ready(function() {
$("#expand-button").bind('click', expandClick($));
document.getElementById("#expand-button").bind("click", expandClick($));
});
function expandClick($) {
$("#outer-container").animate({ "height": "350" }, 500);
$("#expand-button").html("^");
$("#expand-button").bind("click", collapseClick($));
};
function collapseClick($) {
$("#outer-container").animate({ "height": "50" }, 500);
$("#expand-button").html("V");
$("#expand-button").bind("click", expandClick($));
}
The idea is simply that the handler rotates in and out depending on the state of the button. What's actually happening is that as soon as I load the page, the the expandClick function is immediately executed, which sets off an infinite loop of my container bouncing up and down despite nothing being clicked.
Any ideas?
Also, I don't think it should be relevant, but the HTML looks like:
<div id="outer-container" class="container-fluid subsession-collapsed">
<div class="row-fluid" style="height: 50px">
<!-- OTHER STUFF... -->
<div class="span1" id="4">
<button id="expand-button" class="btn-success" data-toggle="collapse" data-target="#expandable">V</button>
</div>
</div>
<br /><br />
<div id="expandable" class="row-fluid collapse">
<div class="span12" style="padding: 0 20px">
<!-- CONTENT -->
</div>
</div>
</div>
Edit:
One SO topic I've used to try and find a solution is this one, but all of the responses have given the same result.