Search code examples
jquerymodal-dialogbuttonclick

Javascript onClick event to open modal


I am using a modal plugin that I discovered from here that works great for my application. I make the modal appear by linking to it this way:

<a href="#myDiv" rel="modal:open">Make Modal Appear</a>

However, I'd like to use the onclick event with a button to make the same plugin work but I can't figure out how to use the "rel=modal:open" code with the onclick event. Without "rel=" command in there, the plugin won't function properly. Any help would be greatly appreciated.


Solution

  • If you mean you want an additional button to do open the modal then you could do something like this:

    <a id="modal-open" href="#myDiv" rel="modal:open">Make Modal Appear</a>
    <button id="another-modal-open" onClick="$('#modal-open').trigger('click');">Also Opens Modal</button>
    

    DEMO: http://jsfiddle.net/aag1wer9/