Is there a way to open the same modal from different js files?

Viewed 48

Is there a way to open the same modal in a single html page from two different js files?

Assuming that I am in the homepage now, when i click a nav button, it calls the openModal function and it should show me the modal below.

Hompage.html

<div id="Homepage-modal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="cart-container">
                <div @click="goToStore()">
                    <div class="button">Click Me</div>
                </div>
            </div>
        </div>
    </div>
</div>

Homepage.js

function (openModal){
    $('#Homepage-modal').modal('show');
}

is there a way for me to click the same button on a different page with a different js file to bring up the same modal from homepage.html without copying and pasting the modal into menu.html

1 Answers

You could put the modals HTML in a subcomponent 'modal' and call that component in the HTML of the component, that you want to display that modal with <modal></modal>.

Related