Here is my HTML and JS:
<div id="mybutton" class="button">
click
</div>
<div id="testcontent">
blah
</div>
<script>
// <![CDATA[
require([
'jquery',
'jquery/ui',
'Magento_Ui/js/modal/modal'
], function ($) {
$(function () {
$('#mybutton').on('click', function(){
$('#testcontent').modal({
title: 'My Title',
autoOpen: true
});
});
});
});
// ]]>
</script>
The Problem is: the modal works only once. After closing it the button does not spawn a second modal.
Best Answer
.modal({...options})
will only set up the modal (and auto open ifautoOpen: true
). You should instruct the modal to open by passing"openModal"
to it (.modal("openModal")
).Try this code: