Use Anymod in a Bootstrap project

Setup

To use mods with Bootstrap 3 or Bootstrap 4, add Anymod where desired, and the Anymod script will load your mod(s) automatically:

<div id="anymod-mklod"></div>
1

Example

Form mods can be a nice addition to a Bootstrap modal:

On-the-fly manipulation

In the event that you're manipulating HTML on the fly, you can use Anymod.render() to render any mods you've added since the initial page load. For example, if we want to render modal content dynamically when an event like show.bs.modal is triggered:

$('#myModal').on('show.bs.modal', function (event) {
  var modal = $(this)
  modal
    .find('.modal-body')
    .html('<div id="anymod-mklod"</div>')
  Anymod.render()
})
1
2
3
4
5
6
7

On-the-fly example

The example below works the same as the first example, but this example uses Anymod.render to render the mod after its HTML is added by the modal initialization:

Re-rendering

You can call Anymod.render() as often as you'd like in your code. This method will not lead to an API call every time; if a mod has already been fetched once, Anymod.render() will use that data instead of making another API call.

TIP

See the section on Anymod.render for more.

Last Updated: 10/5/2018, 9:15:24 PM