Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery, Bootstrap help ? Re: jQuery, Bootstrap help ?

#102043
seanroberts
Member

First of all you need to give you toggle button an id. This way you can better locate this element and apply events to its object. Like so:


​Launch Modal​

Now we can easily target this element. You can make the argument that we don’t need an id to target this element but it is A LOT simpler and faster to do it this way. Now that we can get ahold of this object we need to apply the toggle to its “click” function. JQuery makes this easy for us:


$(document).ready(function() {
$('#modalTrigger').on("click", function(){
$('#myModal').modal('toggle');
});
});

In the code before, the event to toggle that element we handled immediately after the document was ready. What you want is to assign this click event to your element immediately after the document is ready. And inside that click event, you want your toggling action.

Does that help?