I have a single bootstrap modal, which is called from different places, and so the modal contains some
data-* attributes I want to set before showing it. Just using the
.data() offered by jquery does not work.
Suppose you have mark-up like this:
Asking the value is quite easy:
And, according to the documentation, setting the data on a DOM element, should be as easy as
If you would try this in the console, you could verify that does not work. This is where it gets confusing (to me). Apparently the
.data() offered by jquery existed before the HTML5
data-* elements did, and they nicely integrated them. But the
data-* are only loaded once, and never written back to the document.
To still be able to do this, use the
.attr() method instead:
Now I only have to include one modal "template" in my HTML, and set the
data-* attributes to customize the behaviour.