Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Tommi Sipiläinen
5,905 PointsjQuery/Bootsrap -modal opening multiple times.
Hello!
Im not 100% sure if this is the right place to ask, but here goes!
So i have a Bootstrap modal thing.
<div class="modal fade" id="basicModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<div id="mybox"></div>
</div>
</div>
</div>
</div>
<a href="#" class="btn btn-lg btn-success js-navbutton"
data-toggle="modal" data-url="logistiikka"
data-target="#basicModal" value="Update">Logistiikka</a>
<a href="#" class="btn btn-lg btn-success js-navbutton"
data-toggle="modal" data-url="logistiikka/logistiikka-nyt"
data-target="#basicModal" value="Update">Logistiikka nyt</a>
And jquery/ajax to get things going:
$( document ).ready(function() {
//console.log( "ready!" );
$( ".js-navbutton" ).click( function() {
//alert( $( this ).data('url') );
var dataurl = $( this ).data('url');
var request = $.ajax({
url: "http://localhost:8888/virtuaaliturku/" + dataurl,
type: "GET",
dataType: "html"
});
request.done(function(msg) {
$("#mybox").html(msg);
});
request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
});
//prevent.default();
//return false;
});
});
So basically what it does, it uses data-url on links to open different content in modal windows, with jQuery/Ajax. It works! At least it gets right content and puts it to modal (yay!)
My problem is: When i click fist modal link, it opens fine. Nothing wrong. When i click a new one, it opens 2 modals on top of each other. When i open third one, it opens 3 modals and so on.
So if i'm right i need to clear my modal windows after closing them, but i don't have any idea how to do that.
Edit: and it looks like im failing with markdown >.>
1 Answer

Tommi Sipiläinen
5,905 PointsUpdate: here is what is happening http://4dd.fi/virtuaalikirby/logistiikka